pub trait MulDiv<RHS = Self> {
type Output;
// Required methods
fn mul_div_floor(self, num: RHS, denom: RHS) -> Option<Self::Output>;
fn mul_div_ceil(self, num: RHS, denom: RHS) -> Option<Self::Output>;
fn to_underflow_u64(self) -> u64;
}Expand description
Trait for calculating val * num / denom with different rounding modes and overflow
protection.
Implementations of this trait have to ensure that even if the result of the multiplication does
not fit into the type, as long as it would fit after the division the correct result has to be
returned instead of None. None only should be returned if the overall result does not fit
into the type.
This specifically means that e.g. the u64 implementation must, depending on the arguments, be
able to do 128 bit integer multiplication.
Required Associated Types§
Required Methods§
fn mul_div_floor(self, num: RHS, denom: RHS) -> Option<Self::Output>
fn mul_div_ceil(self, num: RHS, denom: RHS) -> Option<Self::Output>
Sourcefn to_underflow_u64(self) -> u64
fn to_underflow_u64(self) -> u64
Return u64 not out of bounds