forked from expr-lang/expr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_math.go
More file actions
114 lines (99 loc) · 2.18 KB
/
func_math.go
File metadata and controls
114 lines (99 loc) · 2.18 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package expr
import (
"math"
"github.com/datasweet/cast"
)
// ABS(x float)
var abs unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Abs(cx)
}
return nil
}
// ACOS(x float)
var acos unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Acos(cx)
}
return nil
}
// ASIN(x float)
var asin unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Asin(cx)
}
return nil
}
// ATAN(x float)
var atan unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Atan(cx)
}
return nil
}
// CEIL(x float)
var ceil unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Ceil(cx)
}
return nil
}
// COS(x float)
var cos unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Cos(cx)
}
return nil
}
// FLOOR(x float)
var floor unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Floor(cx)
}
return nil
}
// LOG(x float)
var log unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Log(cx)
}
return nil
}
// LOG10(x float)
var log10 unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Log10(cx)
}
return nil
}
// POW(x float, y float)
// Used with operator **
var pow binaryOperatorFunc = func(x, y interface{}) interface{} {
cx, okx := cast.AsFloat64(x)
cy, oky := cast.AsFloat64(y)
if !okx || !oky {
return nil
}
return math.Pow(cx, cy)
}
// ROUND(x float)
var round unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Round(cx)
}
return nil
}
// SIN(x float)
var sin unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Sin(cx)
}
return nil
}
// TAN(x float)
var tan unaryOperatorFunc = func(x interface{}) interface{} {
if cx, okx := cast.AsFloat64(x); okx {
return math.Tan(cx)
}
return nil
}