gitee.com/quant1x/num@v0.3.2/internal/functions/arithmetic.go (about) 1 package functions 2 3 import ( 4 "gitee.com/quant1x/num/internal/constraints" 5 "math" 6 ) 7 8 func Add_Go[T constraints.Float](x, y []T) { 9 for i := 0; i < len(x); i++ { 10 x[i] += y[i] 11 } 12 } 13 14 func AddNumber_Go[T constraints.Float](x []T, y T) { 15 for i := 0; i < len(x); i++ { 16 x[i] += y 17 } 18 } 19 20 func Sub_Go[T constraints.Float](x, y []T) { 21 for i := 0; i < len(x); i++ { 22 x[i] -= y[i] 23 } 24 } 25 26 func SubNumber_Go[T constraints.Float](x []T, y T) { 27 for i := 0; i < len(x); i++ { 28 x[i] -= y 29 } 30 } 31 32 func Mul_Go[T constraints.Float](x, y []T) { 33 for i := 0; i < len(x); i++ { 34 x[i] *= y[i] 35 } 36 } 37 38 func MulNumber_Go[T constraints.Float](x []T, y T) { 39 for i := 0; i < len(x); i++ { 40 x[i] *= y 41 } 42 } 43 44 func Div_Go[T constraints.Float](x, y []T) { 45 for i := 0; i < len(x); i++ { 46 x[i] /= y[i] 47 } 48 } 49 50 func DivNumber_Go[T constraints.Float](x []T, y T) { 51 for i := 0; i < len(x); i++ { 52 x[i] /= y 53 } 54 } 55 56 func Abs_Go_F64(x []float64) { 57 for i := 0; i < len(x); i++ { 58 x[i] = math.Abs(x[i]) 59 } 60 } 61 62 func Abs_Go_F32(x []float32) { 63 for i := 0; i < len(x); i++ { 64 x[i] = math.Float32frombits(math.Float32bits(x[i]) &^ (1 << 31)) 65 } 66 } 67 68 func Neg_Go[T constraints.Float](x []T) { 69 for i := 0; i < len(x); i++ { 70 x[i] = -x[i] 71 } 72 } 73 74 func Inv_Go[T constraints.Float](x []T) { 75 for i := 0; i < len(x); i++ { 76 x[i] = 1 / x[i] 77 } 78 }