1 Star 0 Fork 4

王布衣/num

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
max.go 939 Bytes
一键复制 编辑 原始数据 按行查看 历史
package num
import (
"gitee.com/quant1x/num/x32"
"gitee.com/quant1x/num/x64"
)
// Max 纵向计算x最大值
func Max[T Number](x []T) T {
return UnaryOperations1[T](x, x32.Max, x64.Max, __go_max[T])
}
func __go_max[T Number | ~string](x []T) T {
maxValue := x[0]
for _, v := range x[1:] {
if v > maxValue {
maxValue = v
}
}
return maxValue
}
func Max2[T BaseType](x []T) T {
var d any
switch vs := any(x).(type) {
case []float32:
d = Max(vs)
case []float64:
d = Max(vs)
case []int:
d = Max(vs)
case []int8:
d = Max(vs)
case []int16:
d = Max(vs)
case []int32:
d = Max(vs)
case []int64:
d = Max(vs)
case []uint:
d = Max(vs)
case []uint8:
d = Max(vs)
case []uint16:
d = Max(vs)
case []uint32:
d = Max(vs)
case []uint64:
d = Max(vs)
case []uintptr:
d = Max(vs)
case []string:
d = __go_max(vs)
default:
// 其它类型原样返回
panic(TypeError(any(x)))
}
return d.(T)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/num.git
git@gitee.com:quant1x/num.git
quant1x
num
num
v0.3.6

搜索帮助