diff --git a/math.go b/math.go index f2860f5..6c1a1af 100644 --- a/math.go +++ b/math.go @@ -1,6 +1,8 @@ package gmath -import "math" +import ( + "math" +) func Pow[N Number](x, y N) N { return N(math.Pow(float64(x), float64(y))) @@ -9,3 +11,15 @@ func Pow[N Number](x, y N) N { func Abs[N Number](v N) N { return N(math.Abs(float64(v))) } + +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 +} diff --git a/math_test.go b/math_test.go new file mode 100644 index 0000000..4731dd4 --- /dev/null +++ b/math_test.go @@ -0,0 +1,10 @@ +package gmath + +import ( + "fmt" + "testing" +) + +func TestMod(t *testing.T) { + fmt.Println(ModPositive(-1, 10)) +}