-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfunc_add.go
More file actions
107 lines (97 loc) · 1.56 KB
/
Copy pathfunc_add.go
File metadata and controls
107 lines (97 loc) · 1.56 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
package fgbase
import (
"reflect"
)
func addFire2(a, b interface{}) interface{} {
switch a.(type) {
case int8:
{
return a.(int8) + b.(int8)
}
case uint8:
{
return a.(uint8) + b.(uint8)
}
case int16:
{
return a.(int16) + b.(int16)
}
case uint16:
{
return a.(uint16) + b.(uint16)
}
case int32:
{
return a.(int32) + b.(int32)
}
case uint32:
{
return a.(uint32) + b.(uint32)
}
case int64:
{
return a.(int64) + b.(int64)
}
case uint64:
{
return a.(uint64) + b.(uint64)
}
case int:
{
return a.(int) + b.(int)
}
case uint:
{
return a.(uint) + b.(uint)
}
case float32:
{
return a.(float32) + b.(float32)
}
case float64:
{
return a.(float64) + b.(float64)
}
case complex64:
{
return a.(complex64) + b.(complex64)
}
case complex128:
{
return a.(complex128) + b.(complex128)
}
case string:
{
return a.(string) + b.(string)
}
default:
{
return nil
}
}
}
// AddFire fire func for FuncAdd
func AddFire(n *Node) error {
a := n.Srcs[0]
b := n.Srcs[1]
x := n.Dsts[0]
av := a.SrcGet()
bv := b.SrcGet()
if IsEOF(av) || IsEOF(bv) {
x.DstPut(EOF)
return EOF
}
atmp, btmp, same := Promote(n, av, bv)
if !same {
n.LogError("incompatible types for addition (%v+%v)", reflect.TypeOf(a.Val), reflect.TypeOf(b.Val))
x.DstPut(nil)
} else {
x.DstPut(addFire2(atmp, btmp))
}
return nil
}
// FuncAdd adds values and returns the sum (x = a + b).
func FuncAdd(a, b, x Edge) Node {
node := MakeNode("add", []*Edge{&a, &b}, []*Edge{&x}, nil, AddFire)
return node
}