Compare commits

...

6 Commits
v0.0.1 ... main

Author SHA1 Message Date
cf1cd78552 Update go.mod 2024-12-16 19:46:40 +01:00
milarin
baf701ad1e removed useless tests 2024-01-12 18:19:55 +01:00
milarin
a18f1c51cb added Mod and ModPositive 2024-01-12 18:19:35 +01:00
milarin
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
Timon Ringwald
4513bfcb6f added Pow method 2022-08-21 13:49:12 +02:00
4 changed files with 32 additions and 3 deletions

2
go.mod
View File

@ -1,3 +1,3 @@
module git.milar.in/milarin/gmath
module git.tordarus.net/tordarus/gmath
go 1.19

View File

@ -14,6 +14,6 @@ func Max[N Number](a, b N) N {
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)
}

25
math.go Normal file
View File

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

View File

@ -1,5 +1,9 @@
package gmath
type Number interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64
Integer | ~float32 | ~float64
}
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}