Source file
src/runtime/float.go
1
2
3
4
5 package runtime
6
7 import "unsafe"
8
9 var inf = float64frombits(0x7FF0000000000000)
10
11
12 func isNaN(f float64) (is bool) {
13
14 return f != f
15 }
16
17
18 func isFinite(f float64) bool {
19 return !isNaN(f - f)
20 }
21
22
23 func isInf(f float64) bool {
24 return !isNaN(f) && !isFinite(f)
25 }
26
27
28
29
30
31
32
33 func abs(x float64) float64 {
34 const sign = 1 << 63
35 return float64frombits(float64bits(x) &^ sign)
36 }
37
38
39
40 func copysign(x, y float64) float64 {
41 const sign = 1 << 63
42 return float64frombits(float64bits(x)&^sign | float64bits(y)&sign)
43 }
44
45
46 func float64bits(f float64) uint64 {
47 return *(*uint64)(unsafe.Pointer(&f))
48 }
49
50
51
52 func float64frombits(b uint64) float64 {
53 return *(*float64)(unsafe.Pointer(&b))
54 }
55
View as plain text