@@ -20,10 +20,18 @@ import (
20
20
)
21
21
22
22
const (
23
- // prec is the number of bits of precision to use for the Float values.
24
- // To keep things simple, we use the maximum allowable precision on big
25
- // values. This allows us to handle all values we expect in the s2 library.
26
- prec = big .MaxPrec
23
+ // MaxPrec is the number of bits of precision to use for the Float values.
24
+ // To keep things simple, we match the limit used in the C++ library.
25
+ // This allows us to handle all values we expect in the s2 library.
26
+ MaxPrec = 64 << 20 // see C++'s util/math/exactfloat/exactfloat.h
27
+
28
+ // MaxExp is the maximum exponent supported. If a value has an exponent larger than
29
+ // this, it is replaced by infinity (with the appropriate sign).
30
+ MaxExp = 200 * 1000 * 1000 // About 10**(60 million)
31
+
32
+ // MinExp is the minimum exponent supported. If a value has an exponent less than
33
+ // this, it is replaced by zero (with the appropriate sign).
34
+ MinExp = - MaxExp // About 10**(-60 million)
27
35
)
28
36
29
37
// define some commonly referenced values.
@@ -37,28 +45,28 @@ var (
37
45
// are integer multiples of integer powers of 2.
38
46
func precStr (s string ) * big.Float {
39
47
// Explicitly ignoring the bool return for this usage.
40
- f , _ := new (big.Float ).SetPrec (prec ).SetString (s )
48
+ f , _ := new (big.Float ).SetPrec (MaxPrec ).SetString (s )
41
49
return f
42
50
}
43
51
44
52
func precInt (i int64 ) * big.Float {
45
- return new (big.Float ).SetPrec (prec ).SetInt64 (i )
53
+ return new (big.Float ).SetPrec (MaxPrec ).SetInt64 (i )
46
54
}
47
55
48
56
func precFloat (f float64 ) * big.Float {
49
- return new (big.Float ).SetPrec (prec ).SetFloat64 (f )
57
+ return new (big.Float ).SetPrec (MaxPrec ).SetFloat64 (f )
50
58
}
51
59
52
60
func precAdd (a , b * big.Float ) * big.Float {
53
- return new (big.Float ).SetPrec (prec ).Add (a , b )
61
+ return new (big.Float ).SetPrec (MaxPrec ).Add (a , b )
54
62
}
55
63
56
64
func precSub (a , b * big.Float ) * big.Float {
57
- return new (big.Float ).SetPrec (prec ).Sub (a , b )
65
+ return new (big.Float ).SetPrec (MaxPrec ).Sub (a , b )
58
66
}
59
67
60
68
func precMul (a , b * big.Float ) * big.Float {
61
- return new (big.Float ).SetPrec (prec ).Mul (a , b )
69
+ return new (big.Float ).SetPrec (MaxPrec ).Mul (a , b )
62
70
}
63
71
64
72
// PreciseVector represents a point in ℝ³ using high-precision values.
0 commit comments