[][src]Trait rug::ops::DivRounding

pub trait DivRounding<Rhs = Self> {
type Output;
    fn div_trunc(self, rhs: Rhs) -> Self::Output;
fn div_ceil(self, rhs: Rhs) -> Self::Output;
fn div_floor(self, rhs: Rhs) -> Self::Output;
fn div_euc(self, rhs: Rhs) -> Self::Output; }

Rounding variants of division.

Examples

use rug::ops::DivRounding;
struct I(i32);
impl DivRounding<i32> for I {
    type Output = i32;
    fn div_trunc(self, rhs: i32) -> i32 {
        self.0 / rhs
    }
    fn div_ceil(self, rhs: i32) -> i32 {
        let (q, r) = (self.0 / rhs, self.0 % rhs);
        let change = if rhs > 0 { r > 0 } else { r < 0 };
        if change {
            q + 1
        } else {
            q
        }
    }
    fn div_floor(self, rhs: i32) -> i32 {
        let (q, r) = (self.0 / rhs, self.0 % rhs);
        let change = if rhs > 0 { r < 0 } else { r > 0 };
        if change {
            q - 1
        } else {
            q
        }
    }
    fn div_euc(self, rhs: i32) -> i32 {
        let (q, r) = (self.0 / rhs, self.0 % rhs);
        if r < 0 {
            if rhs < 0 {
                q + 1
            } else {
                q - 1
            }
        } else {
            q
        }
    }
}
assert_eq!(I(-10).div_trunc(-3), 3);
assert_eq!(I(-10).div_ceil(-3), 4);
assert_eq!(I(-10).div_floor(-3), 3);
assert_eq!(I(-10).div_euc(-3), 4);

Associated Types

type Output

The resulting type from the division operation.

Loading content...

Required methods

fn div_trunc(self, rhs: Rhs) -> Self::Output

Performs division, rounding the quotient towards zero.

fn div_ceil(self, rhs: Rhs) -> Self::Output

Performs division, rounding the quotient up.

fn div_floor(self, rhs: Rhs) -> Self::Output

Performs division, rounding the quotient down.

fn div_euc(self, rhs: Rhs) -> Self::Output

Performs Euclidean division, rounding the quotient so that the remainder cannot be negative.

Loading content...

Implementations on Foreign Types

impl DivRounding<i8> for i8[src]

type Output = i8

impl<'_> DivRounding<&'_ i8> for i8[src]

type Output = <i8 as DivRounding>::Output

impl<'_> DivRounding<i8> for &'_ i8[src]

type Output = <i8 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ i8> for &'_ i8[src]

type Output = <i8 as DivRounding>::Output

impl DivRounding<i16> for i16[src]

type Output = i16

impl<'_> DivRounding<&'_ i16> for i16[src]

type Output = <i16 as DivRounding>::Output

impl<'_> DivRounding<i16> for &'_ i16[src]

type Output = <i16 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ i16> for &'_ i16[src]

type Output = <i16 as DivRounding>::Output

impl DivRounding<i32> for i32[src]

type Output = i32

impl<'_> DivRounding<&'_ i32> for i32[src]

type Output = <i32 as DivRounding>::Output

impl<'_> DivRounding<i32> for &'_ i32[src]

type Output = <i32 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ i32> for &'_ i32[src]

type Output = <i32 as DivRounding>::Output

impl DivRounding<i64> for i64[src]

type Output = i64

impl<'_> DivRounding<&'_ i64> for i64[src]

type Output = <i64 as DivRounding>::Output

impl<'_> DivRounding<i64> for &'_ i64[src]

type Output = <i64 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ i64> for &'_ i64[src]

type Output = <i64 as DivRounding>::Output

impl DivRounding<i128> for i128[src]

type Output = i128

impl<'_> DivRounding<&'_ i128> for i128[src]

type Output = <i128 as DivRounding>::Output

impl<'_> DivRounding<i128> for &'_ i128[src]

type Output = <i128 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ i128> for &'_ i128[src]

type Output = <i128 as DivRounding>::Output

impl DivRounding<isize> for isize[src]

type Output = isize

impl<'_> DivRounding<&'_ isize> for isize[src]

type Output = <isize as DivRounding>::Output

impl<'_> DivRounding<isize> for &'_ isize[src]

type Output = <isize as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ isize> for &'_ isize[src]

type Output = <isize as DivRounding>::Output

impl DivRounding<u8> for u8[src]

type Output = u8

impl<'_> DivRounding<&'_ u8> for u8[src]

type Output = <u8 as DivRounding>::Output

impl<'_> DivRounding<u8> for &'_ u8[src]

type Output = <u8 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ u8> for &'_ u8[src]

type Output = <u8 as DivRounding>::Output

impl DivRounding<u16> for u16[src]

type Output = u16

impl<'_> DivRounding<&'_ u16> for u16[src]

type Output = <u16 as DivRounding>::Output

impl<'_> DivRounding<u16> for &'_ u16[src]

type Output = <u16 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ u16> for &'_ u16[src]

type Output = <u16 as DivRounding>::Output

impl DivRounding<u32> for u32[src]

type Output = u32

impl<'_> DivRounding<&'_ u32> for u32[src]

type Output = <u32 as DivRounding>::Output

impl<'_> DivRounding<u32> for &'_ u32[src]

type Output = <u32 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ u32> for &'_ u32[src]

type Output = <u32 as DivRounding>::Output

impl DivRounding<u64> for u64[src]

type Output = u64

impl<'_> DivRounding<&'_ u64> for u64[src]

type Output = <u64 as DivRounding>::Output

impl<'_> DivRounding<u64> for &'_ u64[src]

type Output = <u64 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ u64> for &'_ u64[src]

type Output = <u64 as DivRounding>::Output

impl DivRounding<u128> for u128[src]

type Output = u128

impl<'_> DivRounding<&'_ u128> for u128[src]

type Output = <u128 as DivRounding>::Output

impl<'_> DivRounding<u128> for &'_ u128[src]

type Output = <u128 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ u128> for &'_ u128[src]

type Output = <u128 as DivRounding>::Output

impl DivRounding<usize> for usize[src]

type Output = usize

impl<'_> DivRounding<&'_ usize> for usize[src]

type Output = <usize as DivRounding>::Output

impl<'_> DivRounding<usize> for &'_ usize[src]

type Output = <usize as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ usize> for &'_ usize[src]

type Output = <usize as DivRounding>::Output

impl DivRounding<f32> for f32[src]

type Output = f32

impl<'_> DivRounding<&'_ f32> for f32[src]

type Output = <f32 as DivRounding>::Output

impl<'_> DivRounding<f32> for &'_ f32[src]

type Output = <f32 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ f32> for &'_ f32[src]

type Output = <f32 as DivRounding>::Output

impl DivRounding<f64> for f64[src]

type Output = f64

impl<'_> DivRounding<&'_ f64> for f64[src]

type Output = <f64 as DivRounding>::Output

impl<'_> DivRounding<f64> for &'_ f64[src]

type Output = <f64 as DivRounding>::Output

impl<'_, '_> DivRounding<&'_ f64> for &'_ f64[src]

type Output = <f64 as DivRounding>::Output

impl DivRounding<Integer> for i32[src]

type Output = Integer

impl<'i> DivRounding<&'i Integer> for i32[src]

type Output = DivRoundingFromI32Incomplete<'i>

impl<'_> DivRounding<Integer> for &'_ i32[src]

type Output = Integer

impl<'i, '_> DivRounding<&'i Integer> for &'_ i32[src]

type Output = DivRoundingFromI32Incomplete<'i>

impl DivRounding<Integer> for u32[src]

type Output = Integer

impl<'i> DivRounding<&'i Integer> for u32[src]

type Output = DivRoundingFromU32Incomplete<'i>

impl<'_> DivRounding<Integer> for &'_ u32[src]

type Output = Integer

impl<'i, '_> DivRounding<&'i Integer> for &'_ u32[src]

type Output = DivRoundingFromU32Incomplete<'i>

Loading content...

Implementors

impl DivRounding<i32> for Integer[src]

type Output = Integer

impl DivRounding<u32> for Integer[src]

type Output = Integer

impl DivRounding<Integer> for Integer[src]

type Output = Integer

impl<'_> DivRounding<&'_ i32> for Integer[src]

type Output = Integer

impl<'_> DivRounding<&'_ u32> for Integer[src]

type Output = Integer

impl<'_> DivRounding<&'_ Integer> for Integer[src]

type Output = Integer

impl<'_> DivRounding<Integer> for &'_ Integer[src]

type Output = Integer

impl<'i> DivRounding<&'i Integer> for &'i Integer[src]

type Output = DivRoundingIncomplete<'i>

impl<'i> DivRounding<i32> for &'i Integer[src]

type Output = DivRoundingI32Incomplete<'i>

impl<'i> DivRounding<u32> for &'i Integer[src]

type Output = DivRoundingU32Incomplete<'i>

impl<'t, 'i> DivRounding<&'t i32> for &'i Integer[src]

type Output = DivRoundingI32Incomplete<'i>

impl<'t, 'i> DivRounding<&'t u32> for &'i Integer[src]

type Output = DivRoundingU32Incomplete<'i>

Loading content...