goext/mathext/math.go

32 lines
487 B
Go
Raw Permalink Normal View History

2022-10-27 16:00:57 +02:00
package mathext
2022-10-27 17:03:30 +02:00
import "gogs.mikescher.com/BlackForestBytes/goext/langext"
2022-10-27 16:00:57 +02:00
func AvgFloat64(arr []float64) float64 {
return SumFloat64(arr) / float64(len(arr))
}
func SumFloat64(arr []float64) float64 {
sum := 0.0
for _, v := range arr {
sum += v
}
return sum
}
2022-10-27 17:03:30 +02:00
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
}
}