Source file
src/math/nextafter.go
1
2
3
4
5 package math
6
7
8
9
10
11
12
13
14 func Nextafter32(x, y float32) (r float32) {
15 switch {
16 case IsNaN(float64(x)) || IsNaN(float64(y)):
17 r = float32(NaN())
18 case x == y:
19 r = x
20 case x == 0:
21 r = float32(Copysign(float64(Float32frombits(1)), float64(y)))
22 case (y > x) == (x > 0):
23 r = Float32frombits(Float32bits(x) + 1)
24 default:
25 r = Float32frombits(Float32bits(x) - 1)
26 }
27 return
28 }
29
30
31
32
33
34
35
36
37 func Nextafter(x, y float64) (r float64) {
38 switch {
39 case IsNaN(x) || IsNaN(y):
40 r = NaN()
41 case x == y:
42 r = x
43 case x == 0:
44 r = Copysign(Float64frombits(1), y)
45 case (y > x) == (x > 0):
46 r = Float64frombits(Float64bits(x) + 1)
47 default:
48 r = Float64frombits(Float64bits(x) - 1)
49 }
50 return
51 }
52
View as plain text