1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // Nextafter32 returns the next representable float32 value after x towards y.
10 // Nextafter32(x, x) = x
11 // Nextafter32(NaN, y) = NaN
12 // Nextafter32(x, NaN) = NaN
13 func Nextafter32(x, y float32) (r float32) {
15 case IsNaN(float64(x)) || IsNaN(float64(y)): // special case
20 r = float32(Copysign(float64(Float32frombits(1)), float64(y)))
21 case (y > x) == (x > 0):
22 r = Float32frombits(Float32bits(x) + 1)
24 r = Float32frombits(Float32bits(x) - 1)
29 // Nextafter returns the next representable float64 value after x towards y.
32 // Nextafter(x, x) = x
33 // Nextafter(NaN, y) = NaN
34 // Nextafter(x, NaN) = NaN
35 func Nextafter(x, y float64) (r float64) {
37 case IsNaN(x) || IsNaN(y): // special case
42 r = Copysign(Float64frombits(1), y)
43 case (y > x) == (x > 0):
44 r = Float64frombits(Float64bits(x) + 1)
46 r = Float64frombits(Float64bits(x) - 1)