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
valueis written with at its shortest (0.25has two,3.0none);Nonewhen it is not finite or needs more places thansnap_decimalcan 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 ofoperandsor 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.2is0.30000000000000004,7 × 0.1is0.7000000000000001), so a stepper or slider moved in tenths would otherwise land beside the value it shows and miss the end of its range.valueis 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