Documentation ¶
Index ¶
- func Ceil(x float64) float64
- func Clamp[T constraints.Ordered](value T, min T, max T) T
- func Floor(x float64) float64
- func Round(x float64) float64
- func Sum[T constraints.Float | constraints.Integer | constraints.Complex](s []T) T
- func SumBy[T any, R constraints.Float | constraints.Integer | constraints.Complex](s []T, iteratee func(item T) R) R
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clamp ¶
func Clamp[T constraints.Ordered](value T, min T, max T) T
Clamp
value < min: 返回min value > max: 返回max others: 返回value
e.g. (0, -10, 10) => 0 (-42, -10, 10) => -10 (42, -10, 10) => 10
func Round ¶
Round 四舍五入
TODO: 看后续版本Golang math.Round() 的返回值是否与别的语言一致.
!!!: (1) 此方法与"Java(Math.round)"和"JavaScript(Math.round)"一致; (2) Golang 1.17.7原生的math.Round()与"Java(Math.round())"和"JavaScript(Math.round())"不一致,传参为负数的情况.
func Sum ¶
func Sum[T constraints.Float | constraints.Integer | constraints.Complex](s []T) T
Sum 求和
e.g. ([]int{0, 1, 2, 3}) => 6
func SumBy ¶
func SumBy[T any, R constraints.Float | constraints.Integer | constraints.Complex](s []T, iteratee func(item T) R) R
SumBy 求和
@param s 可以为nil(此时返回0) @param iteratee (1) 不能为nil(除非s == nil),否则会导致panic: runtime error: invalid memory address or nil pointer dereference
(2) 传参为T类型,返回值为R类型
e.g.
i := mathKit.SumBy[string, int]([]string{"0", "1", "2"}, func(item string) int { tmp, _ := strconv.Atoi(item) return tmp }) fmt.Println(i) // 3
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.