fn to_u32_floor<T>(x: &T) -> u32Expand description
Extracts the integer part of a fixed-point number as a u32,
truncating the fractional component toward zero.
Fixed-point numbers store their value as inner / DIV, where DIV
is a power of 10 (10^9 for 64-bit types, 10^18 for 128-bit types).
Dividing inner by DIV removes the fractional portion, leaving
the integer part.
§Behavior
| Condition | Returns |
|---|---|
| Integer part negative | 0 |
| Integer part > u32::MAX | u32::MAX |
| Otherwise | Integer part |
§Arguments
x- The fixed-point value to truncate.
§Returns
The integer portion of x, clamped to [0, u32::MAX].
§Examples
ⓘ
// FixedU64 with DIV = 10^9: inner value 300_750_000_000 represents 300.75
let x = FixedU64::from_inner(300_750_000_000);
assert_eq!(to_u32_floor(&x), 300);
// Negative values clamp to 0
let x = FixedI64::saturating_from_integer(-5);
assert_eq!(to_u32_floor(&x), 0);