Trait rug::ops::RemRoundingFrom[][src]

pub trait RemRoundingFrom<Lhs = Self> {
    fn rem_trunc_from(&mut self, lhs: Lhs);
fn rem_ceil_from(&mut self, lhs: Lhs);
fn rem_floor_from(&mut self, lhs: Lhs);
fn rem_euc_from(&mut self, lhs: Lhs); }
Expand description

Compound assignment to the rhs operand and rounding variants of the remainder operation.

Examples

use rug::ops::RemRoundingFrom;
struct I(i32);
impl RemRoundingFrom<i32> for I {
    fn rem_trunc_from(&mut self, lhs: i32) {
        self.0 = lhs % self.0;
    }
    fn rem_ceil_from(&mut self, lhs: i32) {
        let r = lhs % self.0;
        let change = if self.0 > 0 { r > 0 } else { r < 0 };
        self.0 = if change { r - self.0 } else { r };
    }
    fn rem_floor_from(&mut self, lhs: i32) {
        let r = lhs % self.0;
        let change = if self.0 > 0 { r < 0 } else { r > 0 };
        self.0 = if change { r + self.0 } else { r };
    }
    fn rem_euc_from(&mut self, lhs: i32) {
        let r = lhs % self.0;
        self.0 = if r < 0 {
            if self.0 < 0 {
                r - self.0
            } else {
                r + self.0
            }
        } else {
            r
        };
    }
}
let mut rem_ceil = I(3);
rem_ceil.rem_ceil_from(10);
assert_eq!(rem_ceil.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