Files
go-easy-utils/mathx/max.go
2025-07-08 15:26:54 +08:00

22 lines
362 B
Go

package mathx
type Numeric interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
~float32 | ~float64
}
// Max 返回slice中最大值
func Max[T Numeric](slice []T) T {
if len(slice) == 0 {
return 0
}
max := slice[0]
for _, value := range slice {
if value > max {
max = value
}
}
return max
}