Trait MulDiv

Source
pub trait MulDiv: Unsigned {
    // Required methods
    fn checked_mul_div(
        &self,
        numerator: &Self,
        denominator: &Self,
    ) -> Option<Self>;
    fn checked_mul_div_ceil(
        &self,
        numerator: &Self,
        denominator: &Self,
    ) -> Option<Self>;

    // Provided method
    fn checked_mul_div_with_signed_numerator(
        &self,
        numerator: &Self::Signed,
        denominator: &Self,
    ) -> Option<Self::Signed> { ... }
}
Expand description

Perform Mul-Div calculation with bigger range num type.

Required Methods§

Source

fn checked_mul_div(&self, numerator: &Self, denominator: &Self) -> Option<Self>

Calculates floor(self * numerator / denominator) with full precision.

Returns None if the denominator is zero or overflow.

Source

fn checked_mul_div_ceil( &self, numerator: &Self, denominator: &Self, ) -> Option<Self>

Calculates ceil(self * numerator / denominator) with full precision.

Returns None if the denominator is zero or overflow.

Provided Methods§

Source

fn checked_mul_div_with_signed_numerator( &self, numerator: &Self::Signed, denominator: &Self, ) -> Option<Self::Signed>

Calculates floor(self * numerator / denominator) with full precision, where numerator is signed.

Returns None if the denominator is zero or overflow.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl MulDiv for u64

Source§

fn checked_mul_div(&self, numerator: &Self, denominator: &Self) -> Option<Self>

Source§

fn checked_mul_div_ceil( &self, numerator: &Self, denominator: &Self, ) -> Option<Self>

Source§

impl MulDiv for u128

Source§

fn checked_mul_div(&self, numerator: &Self, denominator: &Self) -> Option<Self>

Source§

fn checked_mul_div_ceil( &self, numerator: &Self, denominator: &Self, ) -> Option<Self>

Implementors§