]> Cypherpunks repositories - gostls13.git/commitdiff
math: fix normalization bug in pure-Go sqrt
authorCaleb Spare <cespare@gmail.com>
Thu, 22 Oct 2015 03:35:22 +0000 (20:35 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 23 Oct 2015 18:29:10 +0000 (18:29 +0000)
Fixes #13013

Change-Id: I6cf500eacdce76e303fc1cd92dd1c80eef0986bc
Reviewed-on: https://go-review.googlesource.com/16158
Reviewed-by: Andrew Gerrand <adg@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/math/all_test.go
src/math/sqrt.go

index 53e84765cb8723227dc075cd8be82c85345a986b..4838ffc5e1db91e853707d0e47c8080327f0643b 100644 (file)
@@ -1363,7 +1363,7 @@ var vfmodfSC = []float64{
 var modfSC = [][2]float64{
        {Inf(-1), NaN()}, // [2]float64{Copysign(0, -1), Inf(-1)},
        {Copysign(0, -1), Copysign(0, -1)},
-       {Inf(1), NaN()},  // [2]float64{0, Inf(1)},
+       {Inf(1), NaN()}, // [2]float64{0, Inf(1)},
        {NaN(), NaN()},
 }
 
@@ -1611,6 +1611,7 @@ var vfsqrtSC = []float64{
        0,
        Inf(1),
        NaN(),
+       Float64frombits(2), // subnormal; see https://golang.org/issue/13013
 }
 var sqrtSC = []float64{
        NaN(),
@@ -1619,6 +1620,7 @@ var sqrtSC = []float64{
        0,
        Inf(1),
        NaN(),
+       3.1434555694052576e-162,
 }
 
 var vftanhSC = []float64{
index 23cf2996c2234d4bdc7fce9f351d5c18fa4a1def..96af6e2687d87e6f286ed401ec0a4f4a220f17ab 100644 (file)
@@ -108,7 +108,7 @@ func sqrt(x float64) float64 {
        // normalize x
        exp := int((ix >> shift) & mask)
        if exp == 0 { // subnormal x
-               for ix&1<<shift == 0 {
+               for ix&(1<<shift) == 0 {
                        ix <<= 1
                        exp--
                }