From 3cf61177898fad4e6be85b52083e9c1b508d6568 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Tue, 19 Sep 2023 19:44:35 -0500 Subject: factors.Score: Avoid overflow by using math/big When using really large numbers, factors.Score could overflow, which would cause an incorrect result. Using arbitrary-precision arithmetic fixes this. I only do so above 2^28, since below then factor sums are guaranteed to not overflow, and normal arithmetic is faster. --- factors/factors_test.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'factors/factors_test.go') diff --git a/factors/factors_test.go b/factors/factors_test.go index a18d30b..838186f 100644 --- a/factors/factors_test.go +++ b/factors/factors_test.go @@ -94,6 +94,8 @@ var factorScoreCases = map[uint]float64{ 10: 1.8, 12: 7.0 / 3.0, 120: 3.0, + // number that will use bigScore + 367567200: 62496.0 / 12155.0, } func TestFactorScore(t *testing.T) { -- cgit v1.2.3