diff options
| author | Eoghan Sherry <ejsherry@gmail.com> | 2011-01-19 14:23:59 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2011-01-19 14:23:59 -0500 |
| commit | 13c2e629669c03b440fc1406aff14f72b9450a48 (patch) | |
| tree | 96df4d02ac8a69d77c92299ce561d33ffc7980dc /src/pkg/math/bits.go | |
| parent | 01fad6a6b052292e598e78b30efb89a12ba1ea0e (diff) | |
| download | go-13c2e629669c03b440fc1406aff14f72b9450a48.tar.xz | |
math: handle denormals in Frexp, Ilogb, Ldexp, and Logb
Also:
* document special cases for Frexp and Ldexp
* handle ±Inf in Ldexp
* correctly return -0 on underflow in Ldexp
* test special cases for Ldexp
* test boundary cases for Frexp, Ilogb, Ldexp, and Logb
R=rsc
CC=golang-dev
https://golang.org/cl/3676041
Diffstat (limited to 'src/pkg/math/bits.go')
| -rw-r--r-- | src/pkg/math/bits.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/pkg/math/bits.go b/src/pkg/math/bits.go index 1a97e76799..a1dca3ed69 100644 --- a/src/pkg/math/bits.go +++ b/src/pkg/math/bits.go @@ -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 +} |
