Expand description
Provides a trait for numeric types to perform combined multiplication and division with overflow protection.
The MulDiv
trait provides functions for performing combined multiplication and division for
numeric types and comes with implementations for all the primitive integer types. Three
variants with different rounding characteristics are provided: mul_div_floor()
,
mul_div_round()
and mul_div_ceil()
.
§Example
extern crate muldiv;
use muldiv::MulDiv;
// Calculates 127 * 23 / 42 rounded down
let x = 127u8.mul_div_floor(23, 42);
assert_eq!(x, Some(69));
Macros§
Traits§
- Trait for calculating
val * num / denom
with different rounding modes and overflow protection.