gmath/math.go

26 lines
352 B
Go
Raw Normal View History

2022-08-21 13:49:12 +02:00
package gmath
2024-01-12 18:19:35 +01:00
import (
"math"
)
2022-08-21 13:49:12 +02:00
func Pow[N Number](x, y N) N {
return N(math.Pow(float64(x), float64(y)))
}
2023-04-24 14:53:55 +02:00
func Abs[N Number](v N) N {
return N(math.Abs(float64(v)))
}
2024-01-12 18:19:35 +01:00
func Mod[N Number](a, b N) N {
return N(math.Mod(float64(a), float64(b)))
}
func ModPositive[N Number](a, b N) N {
m := Mod(a, b)
if m >= 0 {
return m
}
return m + b
}