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

fn div_trunc_from(&mut self, lhs: Lhs)[src]

Performs division, rounding the quotient towards zero.

fn div_ceil_from(&mut self, lhs: Lhs)[src]

Performs division, rounding the quotient up.

fn div_floor_from(&mut self, lhs: Lhs)[src]

Performs division, rounding the quotient down.

fn div_euc_from(&mut self, lhs: Lhs)[src]

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

Loading content...

Implementations on Foreign Types

impl DivRoundingFrom<i8> for i8[src]

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

impl DivRoundingFrom<i16> for i16[src]

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

impl DivRoundingFrom<i32> for i32[src]

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

impl DivRoundingFrom<i64> for i64[src]

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

impl DivRoundingFrom<i128> for i128[src]

impl DivRoundingFrom<&'_ i128> for i128[src]

impl DivRoundingFrom<isize> for isize[src]

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

impl DivRoundingFrom<u8> for u8[src]

impl DivRoundingFrom<&'_ u8> for u8[src]

impl DivRoundingFrom<u16> for u16[src]

impl DivRoundingFrom<&'_ u16> for u16[src]

impl DivRoundingFrom<u32> for u32[src]

impl DivRoundingFrom<&'_ u32> for u32[src]

impl DivRoundingFrom<u64> for u64[src]

impl DivRoundingFrom<&'_ u64> for u64[src]

impl DivRoundingFrom<u128> for u128[src]

impl DivRoundingFrom<&'_ u128> for u128[src]

impl DivRoundingFrom<usize> for usize[src]

impl DivRoundingFrom<&'_ usize> for usize[src]

impl DivRoundingFrom<f32> for f32[src]

impl DivRoundingFrom<&'_ f32> for f32[src]

impl DivRoundingFrom<f64> for f64[src]

impl DivRoundingFrom<&'_ f64> for f64[src]

Loading content...

Implementors

impl DivRoundingFrom<&'_ i8> for Integer[src]

impl DivRoundingFrom<&'_ i16> for Integer[src]

impl DivRoundingFrom<&'_ i32> for Integer[src]

impl DivRoundingFrom<&'_ i64> for Integer[src]

impl DivRoundingFrom<&'_ i128> for Integer[src]

impl DivRoundingFrom<&'_ u8> for Integer[src]

impl DivRoundingFrom<&'_ u16> for Integer[src]

impl DivRoundingFrom<&'_ u32> for Integer[src]

impl DivRoundingFrom<&'_ u64> for Integer[src]

impl DivRoundingFrom<&'_ u128> for Integer[src]

impl DivRoundingFrom<&'_ Integer> for Integer[src]

impl DivRoundingFrom<i8> for Integer[src]

impl DivRoundingFrom<i16> for Integer[src]

impl DivRoundingFrom<i32> for Integer[src]

impl DivRoundingFrom<i64> for Integer[src]

impl DivRoundingFrom<i128> for Integer[src]

impl DivRoundingFrom<u8> for Integer[src]

impl DivRoundingFrom<u16> for Integer[src]

impl DivRoundingFrom<u32> for Integer[src]

impl DivRoundingFrom<u64> for Integer[src]

impl DivRoundingFrom<u128> for Integer[src]

impl DivRoundingFrom<Integer> for Integer[src]

Loading content...