Trait rug::ops::DivRoundingAssign[][src]

pub trait DivRoundingAssign<Rhs = Self> {
    fn div_trunc_assign(&mut self, rhs: Rhs);
fn div_ceil_assign(&mut self, rhs: Rhs);
fn div_floor_assign(&mut self, rhs: Rhs);
fn div_euc_assign(&mut self, rhs: Rhs); }
Expand description

Compound assignment and rounding variants of division.

Examples

use rug::ops::DivRoundingAssign;
struct I(i32);
impl DivRoundingAssign<i32> for I {
    fn div_trunc_assign(&mut self, rhs: i32) {
        self.0 /= rhs;
    }
    fn div_ceil_assign(&mut self, rhs: i32) {
        let (q, r) = (self.0 / rhs, self.0 % rhs);
        let change = if rhs > 0 { r > 0 } else { r < 0 };
        self.0 = if change { q + 1 } else { q };
    }
    fn div_floor_assign(&mut self, rhs: i32) {
        let (q, r) = (self.0 / rhs, self.0 % rhs);
        let change = if rhs > 0 { r < 0 } else { r > 0 };
        self.0 = if change { q - 1 } else { q };
    }
    fn div_euc_assign(&mut self, rhs: i32) {
        let (q, r) = (self.0 / rhs, self.0 % rhs);
        self.0 = if r < 0 {
            if rhs < 0 {
                q + 1
            } else {
                q - 1
            }
        } else {
            q
        };
    }
}
let mut div_floor = I(-10);
div_floor.div_floor_assign(3);
assert_eq!(div_floor.0, -4);

Required methods

Performs division, rounding the quotient towards zero.

Performs division, rounding the quotient up.

Performs division, rounding the quotient down.

Performs Euclidean division, rounding the quotient so that the remainder cannot be negative.

Implementations on Foreign Types

Implementors