mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-09-27 03:15:55 +08:00
22 lines
362 B
Go
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
|
|
}
|