mirror of
https://github.com/golang/go
synced 2024-11-12 02:20:23 -07:00
math: fix special cases in Nextafter
Nextafter(0, -1) != -0. R=rsc, golang-dev CC=golang-dev https://golang.org/cl/5467060
This commit is contained in:
parent
420fe22921
commit
f5c211172b
@ -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])
|
||||
}
|
||||
|
@ -8,9 +8,8 @@ package math
|
||||
// If x == y, then x is returned.
|
||||
//
|
||||
// Special cases are:
|
||||
// Nextafter(NaN, y) = NaN
|
||||
// Nextafter(x, NaN) = NaN
|
||||
// Nextafter(0, y) = -0, if y < 0
|
||||
// Nextafter(NaN, y) = NaN
|
||||
// Nextafter(x, NaN) = NaN
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user