代码拉取完成,页面将自动刷新
package common
// NumberT 泛型约束,支持的数值类型
type NumberT interface {
int8 | int16 | int32 | int64 | int | byte | uint16 | uint32 | uint64 | uint | float32 | float64
}
// Max 返回两个数值中的较大值。
func Max[T NumberT](a, b T) T {
if a > b {
return a
}
return b
}
// Min 返回两个数值中的较小值。
func Min[T NumberT](a, b T) T {
if a < b {
return a
}
return b
}
// ConvertInt64 将任意支持的类型转换为 int64。
func ConvertInt64(a interface{}) int64 {
switch v := a.(type) {
case string:
return NewString(v).ToInt64V()
case int8:
return int64(v)
case int16:
return int64(v)
case int32:
return int64(v)
case int64:
return v
case int:
return int64(v)
case byte:
return int64(v)
case uint16:
return int64(v)
case uint32:
return int64(v)
case uint64:
return int64(v)
case uint:
return int64(v)
case float32:
return int64(v)
case float64:
return int64(v)
default:
return 0
}
}
// ConvertInt32 将任意支持的类型转换为 int32。
func ConvertInt32(a interface{}) int32 {
switch v := a.(type) {
case string:
return int32(NewString(v).ToInt64V())
case int8:
return int32(v)
case int16:
return int32(v)
case int32:
return v
case int64:
return int32(v)
case int:
return int32(v)
case byte:
return int32(v)
case uint16:
return int32(v)
case uint32:
return int32(v)
case uint64:
return int32(v)
case uint:
return int32(v)
case float32:
return int32(v)
case float64:
return int32(v)
default:
return 0
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。