-
Notifications
You must be signed in to change notification settings - Fork 47
/
math.go
58 lines (41 loc) · 889 Bytes
/
math.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package jsonlogic
import "math"
func mod(a interface{}, b interface{}) interface{} {
_a := toNumber(a)
_b := toNumber(b)
return math.Mod(_a, _b)
}
func abs(a interface{}) interface{} {
_a := toNumber(a)
return math.Abs(_a)
}
func sum(values interface{}) interface{} {
sum := float64(0)
for _, n := range values.([]interface{}) {
sum += toNumber(n)
}
return sum
}
func minus(values interface{}) interface{} {
_values := toSliceOfNumbers(values)
sum := _values[0]
for i := 1; len(_values) > i; i++ {
sum -= _values[i]
}
return sum
}
func mult(values interface{}) interface{} {
sum := float64(1)
for _, n := range values.([]interface{}) {
sum *= toNumber(n)
}
return sum
}
func div(values interface{}) interface{} {
_values := toSliceOfNumbers(values)
sum := _values[0]
for i := 1; len(_values) > i; i++ {
sum = sum / _values[i]
}
return sum
}