Ai
1 Star 1 Fork 0

liangchao/gx

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
math.go 755 Bytes
Copy Edit Raw Blame History
liangchao authored 2025-03-05 02:01 +08:00 . 修改rand
package gmath
import (
"math"
"gitee.com/makitdone/gx"
)
// 取最小值
func Min[T gx.Number](values ...T) T {
if len(values) == 0 {
panic("Min function called with no arguments")
}
var minValue = values[0]
for _, value := range values {
if value < minValue {
minValue = value
}
}
return minValue
}
// 取最大值
func Max[T gx.Number](values ...T) T {
if len(values) == 0 {
panic("Max function called with no arguments")
}
var maxValue = values[0]
for _, value := range values {
if value > maxValue {
maxValue = value
}
}
return maxValue
}
// Clamp 将值限制在 min 和 max 之间
func Clamp[T gx.Number](value, min, max T) T {
v := math.Min(math.Max(float64(value), float64(min)), float64(max))
return T(v)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/makitdone/gx.git
git@gitee.com:makitdone/gx.git
makitdone
gx
gx
v1.0.1

Search