pub trait RemRoundingAssign<Rhs = Self> {
    fn rem_trunc_assign(&mut self, rhs: Rhs);
    fn rem_ceil_assign(&mut self, rhs: Rhs);
    fn rem_floor_assign(&mut self, rhs: Rhs);
    fn rem_euc_assign(&mut self, rhs: Rhs);
}
Expand description

Compound assignment and rounding variants of the remainder operation.

Examples

use rug::ops::RemRoundingAssign;
struct I(i32);
impl RemRoundingAssign<i32> for I {
    fn rem_trunc_assign(&mut self, rhs: i32) {
        self.0 %= rhs;
    }
    fn rem_ceil_assign(&mut self, rhs: i32) {
        let r = self.0 % rhs;
        let change = if rhs > 0 { r > 0 } else { r < 0 };
        self.0 = if change { r - rhs } else { r };
    }
    fn rem_floor_assign(&mut self, rhs: i32) {
        let r = self.0 % rhs;
        let change = if rhs > 0 { r < 0 } else { r > 0 };
        self.0 = if change { r + rhs } else { r };
    }
    fn rem_euc_assign(&mut self, rhs: i32) {
        let r = self.0 % rhs;
        self.0 = if r < 0 {
            if rhs < 0 {
                r - rhs
            } else {
                r + rhs
            }
        } else {
            r
        };
    }
}
let mut rem_floor = I(-10);
rem_floor.rem_floor_assign(3);
assert_eq!(rem_floor.0, 2);

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

Implementors