Commit 22d4c8bf authored by Caleb Spare's avatar Caleb Spare Committed by Ian Lance Taylor

math: fix normalization bug in pure-Go sqrt

Fixes #13013

Change-Id: I6cf500eacdce76e303fc1cd92dd1c80eef0986bc
Reviewed-on: https://go-review.googlesource.com/16158Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 8ee0fd86
......@@ -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{
......
......@@ -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--
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment