-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmathUtil.go
60 lines (56 loc) · 1.33 KB
/
mathUtil.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
59
60
package gojacego
import "errors"
func toFloat64(value interface{}) (float64, error) {
switch value.(type) {
case int8:
return float64(value.(int8)), nil
case int16:
return float64(value.(int16)), nil
case int32:
return float64(value.(int32)), nil
case int64:
return float64(value.(int64)), nil
case int:
return float64(value.(int)), nil
case float32:
return float64(value.(float32)), nil
case float64:
return float64(value.(float64)), nil
case uint8:
return float64(value.(uint8)), nil
case uint16:
return float64(value.(uint16)), nil
case uint32:
return float64(value.(uint32)), nil
case uint64:
return float64(value.(uint64)), nil
}
return 0, errors.New("cannot convert parameter to float64")
}
func toFloat64Panic(value interface{}) float64 {
switch value.(type) {
case int8:
return float64(value.(int8))
case int16:
return float64(value.(int16))
case int32:
return float64(value.(int32))
case int64:
return float64(value.(int64))
case int:
return float64(value.(int))
case float32:
return float64(value.(float32))
case float64:
return float64(value.(float64))
case uint8:
return float64(value.(uint8))
case uint16:
return float64(value.(uint16))
case uint32:
return float64(value.(uint32))
case uint64:
return float64(value.(uint64))
}
panic("cannot convert parameter to float64")
}