/
TC_cb_math_value.go
82 lines (73 loc) · 2.01 KB
/
TC_cb_math_value.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package ThreadComputation
import (
log "github.com/sirupsen/logrus"
)
func TCValueValueMath(name string, x interface{}, y interface{}) interface{} {
var p float32
p = (x.(*TCValue).P + y.(*TCValue).P)/2
fun := GetMathCallback(x.(*TCValue).Value, y.(*TCValue).Value)
if fun == nil {
return MakeError("No callback for Value")
}
res := fun(name, x.(*TCValue).Value, y.(*TCValue).Value)
log.Debugf("Result of math operation between Value-Value is %v", res)
if res == nil {
return MakeError("Value arithmetic return none")
}
return MakeValue(res, p, 0)
}
func TCValueAnyMath(name string, x interface{}, y interface{}) interface{} {
var p float32
var ry interface{}
switch x.(type) {
case *TCValue:
switch y.(type) {
case *TCValue:
p = (x.(*TCValue).P + y.(*TCValue).P)/2
ry = y.(*TCValue).Value
default:
p = (x.(*TCValue).P + float32(100.0))/2
ry = y
}
fun := GetMathCallback(x.(*TCValue).Value, ry)
if fun == nil {
return MakeError("No callback for Value")
}
res := fun(name, x.(*TCValue).Value, ry)
if res == nil {
return MakeError("Value arithmetic return none")
}
return MakeValue(res, p, 0)
}
return nil
}
func TCAnyValueMath(name string, x interface{}, y interface{}) interface{} {
var p float32
var rx interface{}
switch y.(type) {
case *TCValue:
switch x.(type) {
case *TCValue:
p = (x.(*TCValue).P + y.(*TCValue).P)/2
rx = x.(*TCValue).Value
default:
p = (y.(*TCValue).P + float32(100.0))/2
rx = x
}
fun := GetMathCallback(rx, y.(*TCValue).Value)
if fun == nil {
return MakeError("No callback for Value")
}
res := fun(name, rx, y.(*TCValue).Value)
if res == nil {
return MakeError("Value arithmetic return none")
}
return MakeValue(res, p, 0)
}
return nil
}
func init() {
RegisterMathCallback(Value, Value, TCValueAnyMath)
RegisterMathCallback(Value, Any, TCValueAnyMath)
RegisterMathCallback(Any, Value, TCAnyValueMath)
}