diff options
Diffstat (limited to 'libgo/go/math/log10.go')
-rw-r--r-- | libgo/go/math/log10.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/libgo/go/math/log10.go b/libgo/go/math/log10.go index d880ec2040d..2c09d88f2a1 100644 --- a/libgo/go/math/log10.go +++ b/libgo/go/math/log10.go @@ -27,5 +27,10 @@ func Log2(x float64) float64 { func log2(x float64) float64 { frac, exp := Frexp(x) + // Make sure exact powers of two give an exact answer. + // Don't depend on Log(0.5)*(1/Ln2)+exp being exactly exp-1. + if frac == 0.5 { + return float64(exp - 1) + } return Log(frac)*(1/Ln2) + float64(exp) } |