Commit f5c21117 authored by Charles L. Dorian's avatar Charles L. Dorian Committed by Russ Cox

math: fix special cases in Nextafter

Nextafter(0, -1) != -0.

R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5467060
parent 420fe229
......@@ -1328,12 +1328,26 @@ var modfSC = [][2]float64{
}
var vfnextafterSC = [][2]float64{
{0, 0},
{0, Copysign(0, -1)},
{0, -1},
{0, NaN()},
{Copysign(0, -1), 1},
{Copysign(0, -1), 0},
{Copysign(0, -1), Copysign(0, -1)},
{Copysign(0, -1), -1},
{NaN(), 0},
{NaN(), NaN()},
}
var nextafterSC = []float64{
0,
0,
-4.9406564584124654418e-324, // Float64frombits(0x8000000000000001)
NaN(),
4.9406564584124654418e-324, // Float64frombits(0x0000000000000001)
Copysign(0, -1),
Copysign(0, -1),
-4.9406564584124654418e-324, // Float64frombits(0x8000000000000001)
NaN(),
NaN(),
}
......@@ -2259,7 +2273,7 @@ func TestNextafter(t *testing.T) {
t.Errorf("Nextafter(%g, %g) = %g want %g", vf[i], 10.0, f, nextafter[i])
}
}
for i := 0; i < len(vfmodfSC); i++ {
for i := 0; i < len(vfnextafterSC); i++ {
if f := Nextafter(vfnextafterSC[i][0], vfnextafterSC[i][1]); !alike(nextafterSC[i], f) {
t.Errorf("Nextafter(%g, %g) = %g want %g", vfnextafterSC[i][0], vfnextafterSC[i][1], f, nextafterSC[i])
}
......
......@@ -10,7 +10,6 @@ package math
// Special cases are:
// Nextafter(NaN, y) = NaN
// Nextafter(x, NaN) = NaN
// Nextafter(0, y) = -0, if y < 0
func Nextafter(x, y float64) (r float64) {
// TODO(rsc): Remove manual inlining of IsNaN
// when compiler does it for us
......@@ -26,5 +25,5 @@ func Nextafter(x, y float64) (r float64) {
default:
r = Float64frombits(Float64bits(x) - 1)
}
return r
return
}
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