-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_in.go
39 lines (35 loc) · 837 Bytes
/
build_in.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
package simple_template
import (
"fmt"
"math"
)
func toNumber(inputs []interface{}) (interface{}, error) {
if inputs == nil || len(inputs) == 0 {
return math.NaN(), fmt.Errorf("call toNumber with no argument")
}
if res, ok := TryNumber(inputs[0]); ok {
return res, nil
} else {
return math.NaN(), nil
}
}
func isNaN(inputs []interface{}) (interface{}, error) {
if inputs == nil || len(inputs) == 0 {
return false, fmt.Errorf("call isNaN with no argument")
}
if res, ok := TryNumber(inputs[0]); ok {
return math.IsNaN(res), nil
} else {
return true, nil
}
}
func toBool(inputs []interface{}) (interface{}, error) {
if inputs == nil || len(inputs) == 0 {
return false, fmt.Errorf("call toBool with no argument")
}
if res, ok := TryBool(inputs[0]); ok {
return res, nil
} else {
return false, nil
}
}