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

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

The resulting type from the remainder operation.

Required Methods

Finds the remainder when the quotient is rounded towards zero.

Finds the remainder when the quotient is rounded up.

Finds the remainder when the quotient is rounded down.

Finds the positive remainder from Euclidean division.

Implementations on Foreign Types

impl RemRounding for i8
[src]

[src]

[src]

[src]

[src]

impl RemRounding for i16
[src]

[src]

[src]

[src]

[src]

impl RemRounding for i32
[src]

[src]

[src]

[src]

[src]

impl RemRounding for i64
[src]

[src]

[src]

[src]

[src]

impl RemRounding for isize
[src]

[src]

[src]

[src]

[src]

impl RemRounding<Integer> for i32
[src]

[src]

[src]

[src]

[src]

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

[src]

[src]

[src]

[src]

impl RemRounding<Integer> for u32
[src]

[src]

[src]

[src]

[src]

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

[src]

[src]

[src]

[src]

Implementors