Source file
src/math/modf.go
1
2
3
4
5 package math
6
7
8
9
10
11
12
13
14 func Modf(f float64) (int float64, frac float64) {
15 if haveArchModf {
16 return archModf(f)
17 }
18 return modf(f)
19 }
20
21 func modf(f float64) (int float64, frac float64) {
22 if f < 1 {
23 switch {
24 case f < 0:
25 int, frac = Modf(-f)
26 return -int, -frac
27 case f == 0:
28 return f, f
29 }
30 return 0, f
31 }
32
33 x := Float64bits(f)
34 e := uint(x>>shift)&mask - bias
35
36
37 if e < 64-12 {
38 x &^= 1<<(64-12-e) - 1
39 }
40 int = Float64frombits(x)
41 frac = f - int
42 return
43 }
44
View as plain text