Skip to main content

Module checked

Module checked 

Source
Expand description

Total integer arithmetic: the operations that cannot overflow.

Every function here returns an Option, and None is exactly the case the machine’s +/-/* would have wrapped (or, in debug, panicked). crate::prove carries the proof that the flag is exact rather than a heuristic.

Functions§

checked_add
a + b, or None on overflow. Total: no panic, no wrap-around.
checked_mul
a * b, or None on overflow.
checked_sub
a - b, or None on underflow.
mul_div
a * b / d without overflow in the intermediate product, using a 64-bit widening. Returns None when d == 0 or the true quotient exceeds u32.
saturating_add
a + b, clamped to the type’s maximum.
saturating_sub
a - b, clamped at zero.