Skip to main content

Module numeric

Module numeric 

Source
Expand description

Explicit numeric operations and conversions shared across crate boundaries.

Constants§

DECIMAL_RADIX 🔒
EPSILON
Floating-point comparison tolerance for condition checks.
INTERPOLATION_WINDOW 🔒
U8_MAX_AS_U32 🔒
U32_RANGE_AS_F64 🔒

Functions§

deficit_of
The non-negative shortfall of cur below max.
f64_to_i32_saturating_ceil
Rounds an f64 upward and saturates it to i32.
f64_to_i32_saturating_round
Rounds an f64 to the nearest integer and saturates it to i32.
f64_to_i32_saturating_trunc
Truncates an f64 and saturates it to i32.
f64_to_i64_saturating_floor
Rounds an f64 downward and saturates it to i64.
f64_to_i64_saturating_round
Rounds an f64 to the nearest integer and saturates it to i64.
f64_to_i64_saturating_trunc
Truncates an f64 and saturates it to i64.
f64_to_u8_saturating_trunc
Truncates an f64 and saturates it to u8.
f64_to_u32_saturating_ceil
Rounds an f64 upward and saturates it to u32.
f64_to_u32_saturating_round
Rounds an f64 to the nearest integer and saturates it to u32.
f64_to_u32_saturating_trunc
Truncates an f64 and saturates it to u32.
f64_to_u64_saturating_ceil
Rounds an f64 upward and saturates it to u64.
f64_to_u64_saturating_floor
Rounds an f64 downward and saturates it to u64.
f64_to_u64_saturating_round
Rounds an f64 to the nearest integer and saturates it to u64.
f64_to_u64_saturating_trunc
Truncates an f64 and saturates it to u64.
f64_to_usize_saturating_round
Rounds an f64 to the nearest integer and saturates it to usize.
f64_to_usize_saturating_trunc
Truncates an f64 and saturates it to usize.
float_eq
Compares two floats for equality within EPSILON tolerance.
float_ne
Inverse of float_eq.
i32_to_u8_saturating
Saturates an i32 to the range representable by u8.
i32_to_u32_nonnegative
Converts a nonnegative i32 to u32, clamping negative values to zero.
i64_to_f64
Converts an i64 to f64 with the same rounding as Rust’s native cast.
interpolate_sorted
Interpolates x over points sorted ascending by their first coordinate.
pct_of
cur as a percentage of max, returning 0.0 when max <= 0.
round_to_decimals
Rounds an f64 to the requested number of decimal places.
safe_div
Returns 0.0 on division by zero instead of panicking.
true_mod
True modulo: result has the sign of the divisor (unlike Rust’s %); 0.0 on division by zero.
u32_to_i32_saturating
Saturates a u32 to the range representable by i32.
u64_to_f64
Converts a u64 to f64 with the same rounding as Rust’s native cast.
usize_to_f64
Converts a usize to f64 with the same rounding as Rust’s native cast.
usize_to_u32_saturating
Saturates a usize to the range representable by u32.