diff options
Diffstat (limited to 'libgo/go/math/bits.go')
-rw-r--r-- | libgo/go/math/bits.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/libgo/go/math/bits.go b/libgo/go/math/bits.go index d36cd18d76b..a1dca3ed695 100644 --- a/libgo/go/math/bits.go +++ b/libgo/go/math/bits.go @@ -10,7 +10,7 @@ const ( uvneginf = 0xFFF0000000000000 mask = 0x7FF shift = 64 - 11 - 1 - bias = 1022 + bias = 1023 ) // Inf returns positive infinity if sign >= 0, negative infinity if sign < 0. @@ -47,3 +47,13 @@ func IsInf(f float64, sign int) bool { // return sign >= 0 && x == uvinf || sign <= 0 && x == uvneginf; return sign >= 0 && f > MaxFloat64 || sign <= 0 && f < -MaxFloat64 } + +// normalize returns a normal number y and exponent exp +// satisfying x == y × 2**exp. It assumes x is finite and non-zero. +func normalize(x float64) (y float64, exp int) { + const SmallestNormal = 2.2250738585072014e-308 // 2**-1022 + if Fabs(x) < SmallestNormal { + return x * (1 << 52), -52 + } + return x, 0 +} |