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

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[src]

The resulting type from the division operation.

Loading content...

Required methods

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

Performs division, rounding the quotient towards zero.

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

Performs division, rounding the quotient up.

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

Performs division, rounding the quotient down.

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

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 i8[src]

type Output = Integer

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

type Output = DivRoundingFromI8Incomplete<'i>

impl DivRounding<Integer> for &i8[src]

type Output = Integer

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

type Output = DivRoundingFromI8Incomplete<'i>

impl DivRounding<Integer> for i16[src]

type Output = Integer

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

type Output = DivRoundingFromI16Incomplete<'i>

impl DivRounding<Integer> for &i16[src]

type Output = Integer

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

type Output = DivRoundingFromI16Incomplete<'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 &i32[src]

type Output = Integer

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

type Output = DivRoundingFromI32Incomplete<'i>

impl DivRounding<Integer> for i64[src]

type Output = Integer

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

type Output = DivRoundingFromI64Incomplete<'i>

impl DivRounding<Integer> for &i64[src]

type Output = Integer

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

type Output = DivRoundingFromI64Incomplete<'i>

impl DivRounding<Integer> for i128[src]

type Output = Integer

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

type Output = DivRoundingFromI128Incomplete<'i>

impl DivRounding<Integer> for &i128[src]

type Output = Integer

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

type Output = DivRoundingFromI128Incomplete<'i>

impl DivRounding<Integer> for u8[src]

type Output = Integer

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

type Output = DivRoundingFromU8Incomplete<'i>

impl DivRounding<Integer> for &u8[src]

type Output = Integer

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

type Output = DivRoundingFromU8Incomplete<'i>

impl DivRounding<Integer> for u16[src]

type Output = Integer

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

type Output = DivRoundingFromU16Incomplete<'i>

impl DivRounding<Integer> for &u16[src]

type Output = Integer

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

type Output = DivRoundingFromU16Incomplete<'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>

impl DivRounding<Integer> for u64[src]

type Output = Integer

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

type Output = DivRoundingFromU64Incomplete<'i>

impl DivRounding<Integer> for &u64[src]

type Output = Integer

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

type Output = DivRoundingFromU64Incomplete<'i>

impl DivRounding<Integer> for u128[src]

type Output = Integer

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

type Output = DivRoundingFromU128Incomplete<'i>

impl DivRounding<Integer> for &u128[src]

type Output = Integer

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

type Output = DivRoundingFromU128Incomplete<'i>

Loading content...

Implementors

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

type Output = Integer

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

type Output = Integer

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

type Output = Integer

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

type Output = Integer

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

type Output = Integer

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

type Output = Integer

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

type Output = Integer

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

type Output = Integer

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

type Output = Integer

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

type Output = Integer

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

type Output = Integer

impl DivRounding<i8> for Integer[src]

type Output = Integer

impl DivRounding<i16> for Integer[src]

type Output = Integer

impl DivRounding<i32> for Integer[src]

type Output = Integer

impl DivRounding<i64> for Integer[src]

type Output = Integer

impl DivRounding<i128> for Integer[src]

type Output = Integer

impl DivRounding<u8> for Integer[src]

type Output = Integer

impl DivRounding<u16> for Integer[src]

type Output = Integer

impl DivRounding<u32> for Integer[src]

type Output = Integer

impl DivRounding<u64> for Integer[src]

type Output = Integer

impl DivRounding<u128> 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<i8> for &'i Integer[src]

type Output = DivRoundingI8Incomplete<'i>

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

type Output = DivRoundingI16Incomplete<'i>

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

type Output = DivRoundingI32Incomplete<'i>

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

type Output = DivRoundingI64Incomplete<'i>

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

type Output = DivRoundingI128Incomplete<'i>

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

type Output = DivRoundingU8Incomplete<'i>

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

type Output = DivRoundingU16Incomplete<'i>

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

type Output = DivRoundingU32Incomplete<'i>

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

type Output = DivRoundingU64Incomplete<'i>

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

type Output = DivRoundingU128Incomplete<'i>

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

type Output = DivRoundingI8Incomplete<'i>

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

type Output = DivRoundingI16Incomplete<'i>

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

type Output = DivRoundingI32Incomplete<'i>

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

type Output = DivRoundingI64Incomplete<'i>

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

type Output = DivRoundingI128Incomplete<'i>

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

type Output = DivRoundingU8Incomplete<'i>

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

type Output = DivRoundingU16Incomplete<'i>

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

type Output = DivRoundingU32Incomplete<'i>

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

type Output = DivRoundingU64Incomplete<'i>

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

type Output = DivRoundingU128Incomplete<'i>

Loading content...