Add mathext.Min / mathext.Max

This commit is contained in:
2022-10-27 17:03:30 +02:00
parent 3717eeb515
commit c9e459edac
3 changed files with 56 additions and 8 deletions

View File

@@ -1,5 +1,7 @@
package mathext
import "gogs.mikescher.com/BlackForestBytes/goext/langext"
func AvgFloat64(arr []float64) float64 {
return SumFloat64(arr) / float64(len(arr))
}
@@ -11,3 +13,19 @@ func SumFloat64(arr []float64) float64 {
}
return sum
}
func Max[T langext.OrderedConstraint](v1 T, v2 T) T {
if v1 > v2 {
return v1
} else {
return v2
}
}
func Min[T langext.OrderedConstraint](v1 T, v2 T) T {
if v1 < v2 {
return v1
} else {
return v2
}
}