commit ff2f846ceab47b8be80fc0cb0a4fe23420168b6d Author: Timon Ringwald Date: Tue Aug 16 12:23:03 2022 +0200 min, max and limit implemented diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..121c502 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.milar.in/milarin/gmath + +go 1.19 diff --git a/limits.go b/limits.go new file mode 100644 index 0000000..cd11839 --- /dev/null +++ b/limits.go @@ -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) +} diff --git a/number.go b/number.go new file mode 100644 index 0000000..bd92510 --- /dev/null +++ b/number.go @@ -0,0 +1,5 @@ +package gmath + +type Number interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 +}