min, max and limit implemented

This commit is contained in:
Timon Ringwald 2022-08-16 12:23:03 +02:00
commit ff2f846cea
3 changed files with 27 additions and 0 deletions

3
go.mod Normal file
View File

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

19
limits.go Normal file
View File

@ -0,0 +1,19 @@
package gmath
func Min[N Number](a, b N) N {
if a < b {
return a
}
return b
}
func Max[N Number](a, b N) N {
if a > b {
return a
}
return b
}
func Limit[N Number](v, min, max N) N {
return Min(Max(v, min), max)
}

5
number.go Normal file
View File

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