Compare commits
No commits in common. "main" and "v0.0.1" have entirely different histories.
2
go.mod
2
go.mod
@ -1,3 +1,3 @@
|
|||||||
module git.tordarus.net/tordarus/gmath
|
module git.milar.in/milarin/gmath
|
||||||
|
|
||||||
go 1.19
|
go 1.19
|
||||||
|
@ -14,6 +14,6 @@ func Max[N Number](a, b N) N {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func Clamp[N Number](v, min, max N) N {
|
func Limit[N Number](v, min, max N) N {
|
||||||
return Min(Max(v, min), max)
|
return Min(Max(v, min), max)
|
||||||
}
|
}
|
||||||
|
25
math.go
25
math.go
@ -1,25 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
@ -1,9 +1,5 @@
|
|||||||
package gmath
|
package gmath
|
||||||
|
|
||||||
type Number interface {
|
type Number interface {
|
||||||
Integer | ~float32 | ~float64
|
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64
|
||||||
}
|
|
||||||
|
|
||||||
type Integer interface {
|
|
||||||
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user