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