Documentation
¶
Index ¶
- func Abs[T Number](value T) T
- func Average[T Number](values []T) float64
- func Clamp[T cmp.Ordered](value, min, max T) T
- func Gcd[T constraints.Integer](a, b T) T
- func InRange[T cmp.Ordered](value, min, max T) bool
- func IsPrime[T constraints.Integer](n T) bool
- func Lcm[T constraints.Integer](a, b T) T
- type Number
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
func Abs[T Number](value T) T
Abs returns the absolute value of an integer. For unsigned types, returns the value as-is.
func Average ¶
Average returns the average (mean) of all values in a slice. Returns 0 for empty slice.
func Clamp ¶
Clamp restricts a value to be within a specified range. If value < min, returns min. If value > max, returns max. Otherwise returns value.
func Gcd ¶
func Gcd[T constraints.Integer](a, b T) T
Gcd returns the greatest common divisor of two integers using Euclidean algorithm.
func IsPrime ¶
func IsPrime[T constraints.Integer](n T) bool
IsPrime checks if a number is prime. Returns false for numbers less than 2.
func Lcm ¶
func Lcm[T constraints.Integer](a, b T) T
Lcm returns the least common multiple of two integers.
Types ¶
type Number ¶
type Number interface {
constraints.Integer | constraints.Float
}
Number is a constraint for numeric types.
Click to show internal directories.
Click to hide internal directories.