-
Notifications
You must be signed in to change notification settings - Fork 4
/
go.go
56 lines (47 loc) · 956 Bytes
/
go.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
// +build !avx,!sse
package vecf64
import "math"
// Add performs a̅ + b̅. a̅ will be clobbered
func Add(a, b []float64) {
b = b[:len(a)]
for i, v := range a {
a[i] = v + b[i]
}
}
// Sub performs a̅ - b̅. a̅ will be clobbered
func Sub(a, b []float64) {
b = b[:len(a)]
for i, v := range a {
a[i] = v - b[i]
}
}
// Mul performs a̅ × b̅. a̅ will be clobbered
func Mul(a, b []float64) {
b = b[:len(a)]
for i, v := range a {
a[i] = v * b[i]
}
}
// Div performs a̅ ÷ b̅. a̅ will be clobbered
func Div(a, b []float64) {
b = b[:len(a)]
for i, v := range a {
if b[i] == 0 {
a[i] = math.Inf(0)
continue
}
a[i] = v / b[i]
}
}
// Sqrt performs √a̅ elementwise. a̅ will be clobbered
func Sqrt(a []float64) {
for i, v := range a {
a[i] = math.Sqrt(v)
}
}
// InvSqrt performs 1/√a̅ elementwise. a̅ will be clobbered
func InvSqrt(a []float64) {
for i, v := range a {
a[i] = float64(1) / math.Sqrt(v)
}
}