Documentation
¶
Overview ¶
Package num provides utility functions for number manipulation.
Index ¶
- func Abs(n float64) float64
- func Ceil(n float64, precision ...int) float64
- func Clamp(n, lower, upper float64) float64
- func Floor(n float64, precision ...int) float64
- func InRange(n, start, end float64) bool
- func Max(numbers ...float64) float64
- func MaxBy[T any](collection []T, iteratee func(T) float64) T
- func Mean(numbers ...float64) float64
- func MeanBy[T any](collection []T, iteratee func(T) float64) float64
- func Min(numbers ...float64) float64
- func MinBy[T any](collection []T, iteratee func(T) float64) T
- func Pow(base, exponent float64) float64
- func Random(min, max int) int
- func Round(n float64, precision ...int) float64
- func Sqrt(n float64) float64
- func Sum(numbers ...float64) float64
- func SumBy[T any](collection []T, iteratee func(T) float64) float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ceil ¶
Ceil rounds a number up to the nearest integer or to the specified precision. Example: Ceil(4.3) -> 5, Ceil(4.78, 1) -> 4.8
func Floor ¶
Floor rounds a number down to the nearest integer or to the specified precision. Example: Floor(4.7) -> 4, Floor(4.78, 1) -> 4.7
func InRange ¶
InRange checks if a number is between start and end (inclusive). Example: InRange(3, 2, 4) -> true
func MaxBy ¶
MaxBy returns the maximum value of a slice using the provided iteratee function. Example: MaxBy([]int{1, 2, 3}, func(n int) float64 { return float64(n * n) }) -> 3
func MeanBy ¶
MeanBy returns the mean of values in a slice after applying the iteratee function. Example: MeanBy([]int{1, 2, 3}, func(n int) float64 { return float64(n * 2) }) -> 4
func MinBy ¶
MinBy returns the minimum value of a slice using the provided iteratee function. Example: MinBy([]int{1, 2, 3}, func(n int) float64 { return float64(n * n) }) -> 1
func Random ¶
Random returns a random number between min and max (inclusive). Example: Random(1, 10) -> a random number between 1 and 10
func Round ¶
Round rounds a number to the nearest integer or to the specified precision. Example: Round(4.7) -> 5, Round(4.7, 1) -> 4.7
Types ¶
This section is empty.