Skip to main content

Module num

Module num 

Expand description

Explicit numeric conversions used at UI/model boundaries.

Keeping the necessarily lossy casts here makes their policy consistent: integer narrowing and signed-to-unsigned conversions saturate instead of wrapping, while geometry conversions use Rust’s saturating float-to-int semantics. Call sites stay readable without scattering lint exceptions.

Functions§

decimal_places
How many decimal places value is written with at its shortest (0.25 has two, 3.0 none); None when it is not finite or needs more places than snap_decimal can keep exact.
f32_of_f64
f32_of_i64
f32_of_u32
f64_of_i64
f64_of_u64
f64_of_usize
i32_of_f64
i32_of_usize
i64_of_f32
i64_of_f64
i64_of_usize
isize_of_usize
snap_decimal
value, a sum of operands or of whole multiples of them, as the decimal those operands make: rounded to the most places any of them is written with. Binary floats drift where decimals do not (0.1 + 0.2 is 0.30000000000000004, 7 × 0.1 is 0.7000000000000001), so a stepper or slider moved in tenths would otherwise land beside the value it shows and miss the end of its range. value is returned unchanged when an operand is not a short decimal.
u8_of_f64
u8_of_i64
u32_of_f64
u32_of_i64
u32_of_usize
u64_of_f64
usize_of_f64
usize_of_i32
usize_of_i64
usize_of_isize