Trait rug::ops::DivRoundingFrom [] [src]

pub trait DivRoundingFrom<Lhs = Self> {
    fn div_trunc_from(&mut self, lhs: Lhs);
fn div_ceil_from(&mut self, lhs: Lhs);
fn div_floor_from(&mut self, lhs: Lhs);
fn div_euc_from(&mut self, lhs: Lhs); }

Compound assignment to the rhs operand and rounding variants of division.

Examples

use rug::ops::DivRoundingFrom;
struct I(i32);
impl DivRoundingFrom<i32> for I {
    fn div_trunc_from(&mut self, lhs: i32) {
        self.0 = lhs / self.0;
    }
    fn div_ceil_from(&mut self, lhs: i32) {
        let (q, r) = (lhs / self.0, lhs % self.0);
        let change = if self.0 > 0 { r > 0 } else { r < 0 };
        self.0 = if change { q + 1 } else { q };
    }
    fn div_floor_from(&mut self, lhs: i32) {
        let (q, r) = (lhs / self.0, lhs % self.0);
        let change = if self.0 > 0 { r < 0 } else { r > 0 };
        self.0 = if change { q - 1 } else { q };
    }
    fn div_euc_from(&mut self, lhs: i32) {
        let (q, r) = (lhs / self.0, lhs % self.0);
        self.0 = if r < 0 {
            if self.0 < 0 { q + 1 } else { q - 1 }
        } else {
            q
        };
    }
}
let mut div_ceil = I(3);
div_ceil.div_ceil_from(10);
assert_eq!(div_ceil.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

impl DivRoundingFrom for i8
[src]

[src]

[src]

[src]

[src]

impl<'a> DivRoundingFrom<&'a i8> for i8
[src]

[src]

[src]

[src]

[src]

impl DivRoundingFrom for i16
[src]

[src]

[src]

[src]

[src]

impl<'a> DivRoundingFrom<&'a i16> for i16
[src]

[src]

[src]

[src]

[src]

impl DivRoundingFrom for i32
[src]

[src]

[src]

[src]

[src]

impl<'a> DivRoundingFrom<&'a i32> for i32
[src]

[src]

[src]

[src]

[src]

impl DivRoundingFrom for i64
[src]

[src]

[src]

[src]

[src]

impl<'a> DivRoundingFrom<&'a i64> for i64
[src]

[src]

[src]

[src]

[src]

impl DivRoundingFrom for isize
[src]

[src]

[src]

[src]

[src]

impl<'a> DivRoundingFrom<&'a isize> for isize
[src]

[src]

[src]

[src]

[src]

Implementors