Documentation ¶
Overview ¶
Package math provides math-related utilities.
Index ¶
- Constants
- func Abs[T SignedNumeric](x T) T
- func Clamp[T Numeric](x T, min T, max T) T
- func ClampMax[T Numeric](x T, max T) T
- func ClampMin[T Numeric](x T, min T) T
- func ClosestPowerOf2[T Numeric](x T) T
- func Fastrand[T Unsigned32]() T
- func Fastrandn[T Unsigned32](x T) T
- func Max[T Numeric](x T, y T) T
- func MaxN[T Numeric](x ...T) T
- func Mean[T Numeric](x ...T) T
- func MeanFloat64[T Numeric](x ...T) float64
- func Min[T Numeric](x T, y T) T
- func MinN[T Numeric](x ...T) T
- func NextPowerOf2[T Numeric](x T) T
- func Precision[T constraints.Float](x T, precision int) T
- type Numeric
- type SignedNumeric
- type Unsigned32
Constants ¶
const Version = "v0.3.3"
Version is the current version of the math package.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
func Abs[T SignedNumeric](x T) T
Abs returns the absolute value of the given signed number.
func Clamp ¶ added in v0.1.0
func Clamp[T Numeric](x T, min T, max T) T
Clamp clamps the given value between [min,max] (inclusive).
func ClampMax ¶ added in v0.2.2
func ClampMax[T Numeric](x T, max T) T
ClampMax clamps the given value such that it is not greater than max (inclusive).
func ClampMin ¶ added in v0.2.2
func ClampMin[T Numeric](x T, min T) T
ClampMin clamps the given value such that it is not less than min (inclusive).
func ClosestPowerOf2 ¶ added in v0.2.0
func ClosestPowerOf2[T Numeric](x T) T
ClosestPowerOf2 returns the next T greater than x that is a power of 2.
func Fastrand ¶ added in v0.2.0
func Fastrand[T Unsigned32]() T
Fastrand returns a pseudorandom T in the range [0, 1<<32-1).
func Fastrandn ¶ added in v0.2.0
func Fastrandn[T Unsigned32](x T) T
Fastrandn returns a pseudorandom T in the range [0, min(x, 1<<32-1)). If x is greater than 1<<32-1, it will be clamped.
func MaxN ¶ added in v0.1.0
func MaxN[T Numeric](x ...T) T
MaxN returns the maximum value of the given numbers.
func Mean ¶
func Mean[T Numeric](x ...T) T
Mean returns the truncated average value of all given numbers.
func MeanFloat64 ¶
MeanFloat64 returns the average value of all given numbers.
func MinN ¶ added in v0.1.0
func MinN[T Numeric](x ...T) T
MinN returns the minimum value of the given numbers.
func NextPowerOf2 ¶ added in v0.2.0
func NextPowerOf2[T Numeric](x T) T
NextPowerOf2 returns the next T greater than x that is a power of 2. If x is a power of 2 itself, x is returned.
func Precision ¶ added in v0.3.1
func Precision[T constraints.Float](x T, precision int) T
Precision truncates x to the given precision. If precision is < 0, x is returned unchanged; if x == 0, x is rounded to the nearest integer; otherwise, the precision of x is changed and the resulting value rounded.
Types ¶
type Numeric ¶ added in v0.1.0
type Numeric interface { constraints.Integer | constraints.Float }
Numeric is a constraint that permits any integer or floating point number.
type SignedNumeric ¶ added in v0.1.0
type SignedNumeric interface { constraints.Signed | constraints.Float }
SignedNumeric is a constraint that permits any signed integer or floating point number.
type Unsigned32 ¶ added in v0.2.0
Unsigned32 is a constraint that permits any type that can fit a 32-bit unsigned integer.