diff options
Diffstat (limited to 'common/minmax.go')
-rw-r--r-- | common/minmax.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/common/minmax.go b/common/minmax.go new file mode 100644 index 0000000..b670887 --- /dev/null +++ b/common/minmax.go @@ -0,0 +1,27 @@ +package common + +/* +Golang is a piece of shit. Its creators are paranoids. +*/ + +import ( + "golang.org/x/exp/constraints" +) + +type Number interface { + constraints.Integer | constraints.Float +} + +func Min[T Number](t1 T, t2 T) T { + if t1 < t2 { + return t1 + } + return t2 +} + +func Max[T Number](t1 T, t2 T) T { + if t1 > t2 { + return t1 + } + return t2 +} |