Expand description
The one place a numeric conversion that can lose information is written.
Every function here is total and states what it does at the edge of the
target type: integers become the nearest float, a float narrows to the
nearest float of the smaller width, and a float becomes an integer by
truncation toward zero, saturating at the type’s bounds, with NaN as zero.
Callers use these in place of as, so no conversion in the workspace
needs a lint suppression, and each one is a thin wrapper that inlines away.
Functions§
- f32_eq
- IEEE equality of two
f32values:-0.0equals0.0, NaN equals nothing. - f32_
to_ i64 f32truncated toward zero intoi64, saturating; NaN is zero.- f64_eq
- IEEE equality of two
f64values:-0.0equals0.0, NaN equals nothing. - f64_
to_ f32 f64narrowed to the nearestf32; out-of-range magnitudes become infinities and NaN stays NaN.- f64_
to_ i64 f64truncated toward zero intoi64, saturating; NaN is zero.- f64_
to_ u32 f64truncated toward zero intou32, saturating; NaN and negative values are zero.- f64_
to_ u64 f64truncated toward zero intou64, saturating; NaN and negative values are zero.- f64_
to_ usize f64truncated toward zero intousize, saturating; NaN and negative values are zero.- i64_
to_ f64 - An
i64asf64; exact up to 2^53 in magnitude, rounded to nearest beyond. - low_u8
- The low eight bits of
value; the rest are discarded on purpose. - low_u16
- The low sixteen bits of
value; the rest are discarded on purpose. - u64_
to_ f64 - A count as
f64; exact up to 2^53, rounded to nearest beyond. - u64_
to_ f32_ unit - A 24-bit sample
bitsscaled to[0, 1); exact inf32. - u64_
to_ u32 - A
u64asu32, saturating atu32::MAX. - usize_
to_ f32 - A count as
f32; exact up to 2^24, rounded to nearest beyond. - usize_
to_ f64 - A count as
f64; exact up to 2^53, rounded to nearest beyond. - usize_
to_ u32 - An index as
u32, saturating atu32::MAX.