Skip to main content

Module numeric

Module numeric 

Source
Expand description

Numeric helper utilities

Functionsยง

approx_eq
Approximately equal for f64 within epsilon
cross_product
3D cross product
degrees_to_radians
Convert degrees to radians
dot_product
Dot product of two vectors
euclidean_distance
Euclidean distance between equal-length vectors
factorial
Factorial for n up to 20 (fits in u128)
fibonacci
n-th Fibonacci number (F(0)=0)
gcd_u64
Greatest common divisor (Euclidean algorithm)
is_even
True if n is even
is_odd
True if n is odd
is_prime
Check primality by trial division
lcm_u64
Least common multiple
lerp
Linear interpolation between a and b by t in [0,1]
manhattan_distance
Manhattan distance between equal-length vectors
map_range
Map value from one range to another
next_prime
Next prime greater than or equal to n
normalize
Normalize x to [0,1] given min and max
prev_prime
Previous prime strictly less than n
radians_to_degrees
Convert radians to degrees
sigmoid
Logistic sigmoid function
signum_zero
Signum with zero for integers
sum_i64_saturating
Saturating sum for i64 slice