Trait rug::ops::DivRoundingFrom

source ·
pub trait DivRoundingFrom<Lhs = Self> {
    // Required methods
    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);
}
Expand description

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§

source

fn div_trunc_from(&mut self, lhs: Lhs)

Performs division, rounding the quotient towards zero.

source

fn div_ceil_from(&mut self, lhs: Lhs)

Performs division, rounding the quotient up.

source

fn div_floor_from(&mut self, lhs: Lhs)

Performs division, rounding the quotient down.

source

fn div_euc_from(&mut self, lhs: Lhs)

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

Implementations on Foreign Types§

source§

impl DivRoundingFrom for f32

source§

fn div_trunc_from(&mut self, lhs: f32)

source§

fn div_ceil_from(&mut self, lhs: f32)

source§

fn div_floor_from(&mut self, lhs: f32)

source§

fn div_euc_from(&mut self, lhs: f32)

source§

impl DivRoundingFrom for f64

source§

fn div_trunc_from(&mut self, lhs: f64)

source§

fn div_ceil_from(&mut self, lhs: f64)

source§

fn div_floor_from(&mut self, lhs: f64)

source§

fn div_euc_from(&mut self, lhs: f64)

source§

impl DivRoundingFrom for i8

source§

fn div_trunc_from(&mut self, lhs: i8)

source§

fn div_ceil_from(&mut self, lhs: i8)

source§

fn div_floor_from(&mut self, lhs: i8)

source§

fn div_euc_from(&mut self, lhs: i8)

source§

impl DivRoundingFrom for i16

source§

fn div_trunc_from(&mut self, lhs: i16)

source§

fn div_ceil_from(&mut self, lhs: i16)

source§

fn div_floor_from(&mut self, lhs: i16)

source§

fn div_euc_from(&mut self, lhs: i16)

source§

impl DivRoundingFrom for i32

source§

fn div_trunc_from(&mut self, lhs: i32)

source§

fn div_ceil_from(&mut self, lhs: i32)

source§

fn div_floor_from(&mut self, lhs: i32)

source§

fn div_euc_from(&mut self, lhs: i32)

source§

impl DivRoundingFrom for i64

source§

fn div_trunc_from(&mut self, lhs: i64)

source§

fn div_ceil_from(&mut self, lhs: i64)

source§

fn div_floor_from(&mut self, lhs: i64)

source§

fn div_euc_from(&mut self, lhs: i64)

source§

impl DivRoundingFrom for i128

source§

fn div_trunc_from(&mut self, lhs: i128)

source§

fn div_ceil_from(&mut self, lhs: i128)

source§

fn div_floor_from(&mut self, lhs: i128)

source§

fn div_euc_from(&mut self, lhs: i128)

source§

impl DivRoundingFrom for isize

source§

fn div_trunc_from(&mut self, lhs: isize)

source§

fn div_ceil_from(&mut self, lhs: isize)

source§

fn div_floor_from(&mut self, lhs: isize)

source§

fn div_euc_from(&mut self, lhs: isize)

source§

impl DivRoundingFrom for u8

source§

fn div_trunc_from(&mut self, lhs: u8)

source§

fn div_ceil_from(&mut self, lhs: u8)

source§

fn div_floor_from(&mut self, lhs: u8)

source§

fn div_euc_from(&mut self, lhs: u8)

source§

impl DivRoundingFrom for u16

source§

fn div_trunc_from(&mut self, lhs: u16)

source§

fn div_ceil_from(&mut self, lhs: u16)

source§

fn div_floor_from(&mut self, lhs: u16)

source§

fn div_euc_from(&mut self, lhs: u16)

source§

impl DivRoundingFrom for u32

source§

fn div_trunc_from(&mut self, lhs: u32)

source§

fn div_ceil_from(&mut self, lhs: u32)

source§

fn div_floor_from(&mut self, lhs: u32)

source§

fn div_euc_from(&mut self, lhs: u32)

source§

impl DivRoundingFrom for u64

source§

fn div_trunc_from(&mut self, lhs: u64)

source§

fn div_ceil_from(&mut self, lhs: u64)

source§

fn div_floor_from(&mut self, lhs: u64)

source§

fn div_euc_from(&mut self, lhs: u64)

source§

impl DivRoundingFrom for u128

source§

fn div_trunc_from(&mut self, lhs: u128)

source§

fn div_ceil_from(&mut self, lhs: u128)

source§

fn div_floor_from(&mut self, lhs: u128)

source§

fn div_euc_from(&mut self, lhs: u128)

source§

impl DivRoundingFrom for usize

source§

fn div_trunc_from(&mut self, lhs: usize)

source§

fn div_ceil_from(&mut self, lhs: usize)

source§

fn div_floor_from(&mut self, lhs: usize)

source§

fn div_euc_from(&mut self, lhs: usize)

source§

impl DivRoundingFrom<&f32> for f32

source§

fn div_trunc_from(&mut self, lhs: &f32)

source§

fn div_ceil_from(&mut self, lhs: &f32)

source§

fn div_floor_from(&mut self, lhs: &f32)

source§

fn div_euc_from(&mut self, lhs: &f32)

source§

impl DivRoundingFrom<&f64> for f64

source§

fn div_trunc_from(&mut self, lhs: &f64)

source§

fn div_ceil_from(&mut self, lhs: &f64)

source§

fn div_floor_from(&mut self, lhs: &f64)

source§

fn div_euc_from(&mut self, lhs: &f64)

source§

impl DivRoundingFrom<&i8> for i8

source§

fn div_trunc_from(&mut self, lhs: &i8)

source§

fn div_ceil_from(&mut self, lhs: &i8)

source§

fn div_floor_from(&mut self, lhs: &i8)

source§

fn div_euc_from(&mut self, lhs: &i8)

source§

impl DivRoundingFrom<&i16> for i16

source§

fn div_trunc_from(&mut self, lhs: &i16)

source§

fn div_ceil_from(&mut self, lhs: &i16)

source§

fn div_floor_from(&mut self, lhs: &i16)

source§

fn div_euc_from(&mut self, lhs: &i16)

source§

impl DivRoundingFrom<&i32> for i32

source§

fn div_trunc_from(&mut self, lhs: &i32)

source§

fn div_ceil_from(&mut self, lhs: &i32)

source§

fn div_floor_from(&mut self, lhs: &i32)

source§

fn div_euc_from(&mut self, lhs: &i32)

source§

impl DivRoundingFrom<&i64> for i64

source§

fn div_trunc_from(&mut self, lhs: &i64)

source§

fn div_ceil_from(&mut self, lhs: &i64)

source§

fn div_floor_from(&mut self, lhs: &i64)

source§

fn div_euc_from(&mut self, lhs: &i64)

source§

impl DivRoundingFrom<&i128> for i128

source§

fn div_trunc_from(&mut self, lhs: &i128)

source§

fn div_ceil_from(&mut self, lhs: &i128)

source§

fn div_floor_from(&mut self, lhs: &i128)

source§

fn div_euc_from(&mut self, lhs: &i128)

source§

impl DivRoundingFrom<&isize> for isize

source§

fn div_trunc_from(&mut self, lhs: &isize)

source§

fn div_ceil_from(&mut self, lhs: &isize)

source§

fn div_floor_from(&mut self, lhs: &isize)

source§

fn div_euc_from(&mut self, lhs: &isize)

source§

impl DivRoundingFrom<&u8> for u8

source§

fn div_trunc_from(&mut self, lhs: &u8)

source§

fn div_ceil_from(&mut self, lhs: &u8)

source§

fn div_floor_from(&mut self, lhs: &u8)

source§

fn div_euc_from(&mut self, lhs: &u8)

source§

impl DivRoundingFrom<&u16> for u16

source§

fn div_trunc_from(&mut self, lhs: &u16)

source§

fn div_ceil_from(&mut self, lhs: &u16)

source§

fn div_floor_from(&mut self, lhs: &u16)

source§

fn div_euc_from(&mut self, lhs: &u16)

source§

impl DivRoundingFrom<&u32> for u32

source§

fn div_trunc_from(&mut self, lhs: &u32)

source§

fn div_ceil_from(&mut self, lhs: &u32)

source§

fn div_floor_from(&mut self, lhs: &u32)

source§

fn div_euc_from(&mut self, lhs: &u32)

source§

impl DivRoundingFrom<&u64> for u64

source§

fn div_trunc_from(&mut self, lhs: &u64)

source§

fn div_ceil_from(&mut self, lhs: &u64)

source§

fn div_floor_from(&mut self, lhs: &u64)

source§

fn div_euc_from(&mut self, lhs: &u64)

source§

impl DivRoundingFrom<&u128> for u128

source§

fn div_trunc_from(&mut self, lhs: &u128)

source§

fn div_ceil_from(&mut self, lhs: &u128)

source§

fn div_floor_from(&mut self, lhs: &u128)

source§

fn div_euc_from(&mut self, lhs: &u128)

source§

impl DivRoundingFrom<&usize> for usize

source§

fn div_trunc_from(&mut self, lhs: &usize)

source§

fn div_ceil_from(&mut self, lhs: &usize)

source§

fn div_floor_from(&mut self, lhs: &usize)

source§

fn div_euc_from(&mut self, lhs: &usize)

Implementors§