[][src]Trait rug::ops::RemRounding

pub trait RemRounding<Rhs = Self> {
    type Output;
    fn rem_trunc(self, rhs: Rhs) -> Self::Output;
fn rem_ceil(self, rhs: Rhs) -> Self::Output;
fn rem_floor(self, rhs: Rhs) -> Self::Output;
fn rem_euc(self, rhs: Rhs) -> Self::Output; }

Rounding variants of the remainder operation.

Examples

use rug::ops::RemRounding;
struct I(i32);
impl RemRounding<i32> for I {
    type Output = i32;
    fn rem_trunc(self, rhs: i32) -> i32 {
        self.0 % rhs
    }
    fn rem_ceil(self, rhs: i32) -> i32 {
        let r = self.0 % rhs;
        let change = if rhs > 0 { r > 0 } else { r < 0 };
        if change {
            r - rhs
        } else {
            r
        }
    }
    fn rem_floor(self, rhs: i32) -> i32 {
        let r = self.0 % rhs;
        let change = if rhs > 0 { r < 0 } else { r > 0 };
        if change {
            r + rhs
        } else {
            r
        }
    }
    fn rem_euc(self, rhs: i32) -> i32 {
        let r = self.0 % rhs;
        if r < 0 {
            if rhs < 0 {
                r - rhs
            } else {
                r + rhs
            }
        } else {
            r
        }
    }
}
assert_eq!(I(-10).rem_trunc(-3), -1);
assert_eq!(I(-10).rem_ceil(-3), 2);
assert_eq!(I(-10).rem_floor(-3), -1);
assert_eq!(I(-10).rem_euc(-3), 2);

Associated Types

type Output

The resulting type from the remainder operation.

Loading content...

Required methods

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

Finds the remainder when the quotient is rounded towards zero.

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

Finds the remainder when the quotient is rounded up.

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

Finds the remainder when the quotient is rounded down.

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

Finds the positive remainder from Euclidean division.

Loading content...

Implementations on Foreign Types

impl RemRounding<i8> for i8[src]

type Output = i8

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

type Output = <i8 as RemRounding>::Output

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

type Output = <i8 as RemRounding>::Output

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

type Output = <i8 as RemRounding>::Output

impl RemRounding<i16> for i16[src]

type Output = i16

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

type Output = <i16 as RemRounding>::Output

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

type Output = <i16 as RemRounding>::Output

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

type Output = <i16 as RemRounding>::Output

impl RemRounding<i32> for i32[src]

type Output = i32

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

type Output = <i32 as RemRounding>::Output

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

type Output = <i32 as RemRounding>::Output

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

type Output = <i32 as RemRounding>::Output

impl RemRounding<i64> for i64[src]

type Output = i64

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

type Output = <i64 as RemRounding>::Output

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

type Output = <i64 as RemRounding>::Output

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

type Output = <i64 as RemRounding>::Output

impl RemRounding<i128> for i128[src]

type Output = i128

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

type Output = <i128 as RemRounding>::Output

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

type Output = <i128 as RemRounding>::Output

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

type Output = <i128 as RemRounding>::Output

impl RemRounding<isize> for isize[src]

type Output = isize

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

type Output = <isize as RemRounding>::Output

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

type Output = <isize as RemRounding>::Output

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

type Output = <isize as RemRounding>::Output

impl RemRounding<f32> for f32[src]

type Output = f32

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

type Output = <f32 as RemRounding>::Output

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

type Output = <f32 as RemRounding>::Output

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

type Output = <f32 as RemRounding>::Output

impl RemRounding<f64> for f64[src]

type Output = f64

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

type Output = <f64 as RemRounding>::Output

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

type Output = <f64 as RemRounding>::Output

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

type Output = <f64 as RemRounding>::Output

impl RemRounding<Integer> for i32[src]

type Output = Integer

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

type Output = RemRoundingFromI32Incomplete<'i>

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

type Output = Integer

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

type Output = RemRoundingFromI32Incomplete<'i>

impl RemRounding<Integer> for u32[src]

type Output = Integer

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

type Output = RemRoundingFromU32Incomplete<'i>

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

type Output = Integer

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

type Output = RemRoundingFromU32Incomplete<'i>

Loading content...

Implementors

impl RemRounding<i32> for Integer[src]

type Output = Integer

impl RemRounding<u32> for Integer[src]

type Output = Integer

impl RemRounding<Integer> for Integer[src]

type Output = Integer

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

type Output = Integer

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

type Output = Integer

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

type Output = Integer

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

type Output = Integer

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

type Output = RemRoundingIncomplete<'i>

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

type Output = RemRoundingI32Incomplete<'i>

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

type Output = RemRoundingU32Incomplete<'i>

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

type Output = RemRoundingI32Incomplete<'i>

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

type Output = RemRoundingU32Incomplete<'i>

Loading content...