-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
math.go
44 lines (34 loc) · 1.03 KB
/
math.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
package nodes
import (
"github.com/EliCDavis/vector"
)
// ============================================================================
type SumNode = StructNode[float64, SumData[float64]]
type SumData[T vector.Number] struct {
Values []NodeOutput[T]
}
func (cn SumData[T]) Process() (T, error) {
var total T
for _, v := range cn.Values {
total += v.Value()
}
return total, nil
}
// ============================================================================
type DifferenceNode = StructNode[float64, DifferenceData[float64]]
type DifferenceData[T vector.Number] struct {
A NodeOutput[T]
B NodeOutput[T]
}
func (cn DifferenceData[T]) Process() (T, error) {
return cn.A.Value() - cn.B.Value(), nil
}
// ============================================================================
type DivideNode = StructNode[float64, DivideData[float64]]
type DivideData[T vector.Number] struct {
Dividend NodeOutput[T]
Divisor NodeOutput[T]
}
func (cn DivideData[T]) Process() (T, error) {
return cn.Dividend.Value() / cn.Divisor.Value(), nil
}