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.
11 // Nextafter32(x, x) = x
12 // Nextafter32(NaN, y) = NaN
13 // Nextafter32(x, NaN) = NaN
14 func Nextafter32(x, y float32) (r float32) {
16 case IsNaN(float64(x)) || IsNaN(float64(y)): // special case
21 r = float32(Copysign(float64(Float32frombits(1)), float64(y)))
22 case (y > x) == (x > 0):
23 r = Float32frombits(Float32bits(x) + 1)
25 r = Float32frombits(Float32bits(x) - 1)
30 // Nextafter returns the next representable float64 value after x towards y.
34 // Nextafter(x, x) = x
35 // Nextafter(NaN, y) = NaN
36 // Nextafter(x, NaN) = NaN
37 func Nextafter(x, y float64) (r float64) {
39 case IsNaN(x) || IsNaN(y): // special case
44 r = Copysign(Float64frombits(1), y)
45 case (y > x) == (x > 0):
46 r = Float64frombits(Float64bits(x) + 1)
48 r = Float64frombits(Float64bits(x) - 1)