...
Source file
src/math/mod.go
Documentation: math
1
2
3
4
5 package math
6
7
10
11
12
13
14
15
16
17
18
19
20
21 func Mod(x, y float64) float64 {
22 if haveArchMod {
23 return archMod(x, y)
24 }
25 return mod(x, y)
26 }
27
28 func mod(x, y float64) float64 {
29 if y == 0 || IsInf(x, 0) || IsNaN(x) || IsNaN(y) {
30 return NaN()
31 }
32 y = Abs(y)
33
34 yfr, yexp := Frexp(y)
35 r := x
36 if x < 0 {
37 r = -x
38 }
39
40 for r >= y {
41 rfr, rexp := Frexp(r)
42 if rfr < yfr {
43 rexp = rexp - 1
44 }
45 r = r - Ldexp(y, rexp-yexp)
46 }
47 if x < 0 {
48 r = -r
49 }
50 return r
51 }
52
View as plain text