Compare commits

..

4 Commits
v0.0.2 ... main

Author SHA1 Message Date
baf701ad1e removed useless tests 2024-01-12 18:19:55 +01:00
a18f1c51cb added Mod and ModPositive 2024-01-12 18:19:35 +01:00
de82000934 added Abs 2023-04-24 14:53:55 +02:00
Timon Ringwald
82073f40ae renamed limit to clamp 2022-08-21 20:08:34 +02:00
2 changed files with 20 additions and 2 deletions

View File

@ -14,6 +14,6 @@ func Max[N Number](a, b N) N {
return b return b
} }
func Limit[N Number](v, min, max N) N { func Clamp[N Number](v, min, max N) N {
return Min(Max(v, min), max) return Min(Max(v, min), max)
} }

20
math.go
View File

@ -1,7 +1,25 @@
package gmath package gmath
import "math" import (
"math"
)
func Pow[N Number](x, y N) N { func Pow[N Number](x, y N) N {
return N(math.Pow(float64(x), float64(y))) return N(math.Pow(float64(x), float64(y)))
} }
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
}