Documentation
¶
Overview ¶
Package mathutil provides generic numeric utility functions for comparable and ordered types.
Index ¶
- func Abs[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~float32 | ~float64](v T) T
- func Average[T Number](values []T) float64
- func CeilDiv[T ~int | ~int32 | ~int64](a, b T) T
- func Clamp[T cmp.Ordered](val, lo, hi T) T
- func DivMod[T ~int | ~int32 | ~int64](a, b T) (T, T)
- func InRange[T cmp.Ordered](val, lo, hi T) bool
- func MaxSlice[T cmp.Ordered](values []T) T
- func MinSlice[T cmp.Ordered](values []T) T
- func Percentage(part, total float64) float64
- func RoundTo(val float64, places int) float64
- func SafeDiv[T Number](a, b, defaultVal T) T
- func Sum[T Number](values []T) T
- type Number
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CeilDiv ¶
CeilDiv performs integer division rounding up (ceiling division). Both a and b must be non-negative (a >= 0, b > 0). For negative values, use standard integer division instead.
func Percentage ¶
Percentage calculates (part / total * 100) safely, returning 0 if total is 0.
Types ¶
Click to show internal directories.
Click to hide internal directories.