func TestNextafter64(t *testing.T) {
for i := 0; i < len(vf); i++ {
- if f := Nextafter64(vf[i], 10); nextafter64[i] != f {
+ if f := Nextafter(vf[i], 10); nextafter64[i] != f {
t.Errorf("Nextafter64(%g, %g) = %g want %g", vf[i], 10.0, f, nextafter64[i])
}
}
for i := 0; i < len(vfnextafter64SC); i++ {
- if f := Nextafter64(vfnextafter64SC[i][0], vfnextafter64SC[i][1]); !alike(nextafter64SC[i], f) {
+ if f := Nextafter(vfnextafter64SC[i][0], vfnextafter64SC[i][1]); !alike(nextafter64SC[i], f) {
t.Errorf("Nextafter64(%g, %g) = %g want %g", vfnextafter64SC[i][0], vfnextafter64SC[i][1], f, nextafter64SC[i])
}
}
func BenchmarkNextafter64(b *testing.B) {
for i := 0; i < b.N; i++ {
- Nextafter64(.5, 1)
+ Nextafter(.5, 1)
}
}
"22.222222222222222",
"long:2." + strings.Repeat("2", 4000) + "e+1",
- // Exactly halfway between 1 and math.Nextafter64(1, 2).
+ // Exactly halfway between 1 and math.Nextafter(1, 2).
// Round to even (down).
"1.00000000000000011102230246251565404236316680908203125",
// Slightly lower; still round down.
}
// r must be strictly between f0 and f1, the floats bracketing f.
- f0 := math.Nextafter64(f, math.Inf(-1))
- f1 := math.Nextafter64(f, math.Inf(+1))
+ f0 := math.Nextafter(f, math.Inf(-1))
+ f1 := math.Nextafter(f, math.Inf(+1))
// For f to be correct, r must be closer to f than to f0 or f1.
df := delta(r, f)
return
}
-// Nextafter64 returns the next representable float64 value after x towards y.
+// Nextafter returns the next representable float64 value after x towards y.
// Special cases:
// Nextafter64(x, x) = x
// Nextafter64(NaN, y) = NaN
// Nextafter64(x, NaN) = NaN
-func Nextafter64(x, y float64) (r float64) {
+func Nextafter(x, y float64) (r float64) {
switch {
case IsNaN(x) || IsNaN(y): // special case
r = NaN()
}
return
}
-
-// Nextafter is the same as Nextafter64.
-// It is provided for backward-compatibility only.
-func Nextafter(x, y float64) float64 {
- return Nextafter64(x, y)
-}