Trait rug::ops::RemRoundingAssign
source · pub trait RemRoundingAssign<Rhs = Self> {
// Required methods
fn rem_trunc_assign(&mut self, rhs: Rhs);
fn rem_ceil_assign(&mut self, rhs: Rhs);
fn rem_floor_assign(&mut self, rhs: Rhs);
fn rem_euc_assign(&mut self, rhs: Rhs);
}
Expand description
Compound assignment and rounding variants of the remainder operation.
§Examples
use rug::ops::RemRoundingAssign;
struct I(i32);
impl RemRoundingAssign<i32> for I {
fn rem_trunc_assign(&mut self, rhs: i32) {
self.0 %= rhs;
}
fn rem_ceil_assign(&mut self, rhs: i32) {
let r = self.0 % rhs;
let change = if rhs > 0 { r > 0 } else { r < 0 };
self.0 = if change { r - rhs } else { r };
}
fn rem_floor_assign(&mut self, rhs: i32) {
let r = self.0 % rhs;
let change = if rhs > 0 { r < 0 } else { r > 0 };
self.0 = if change { r + rhs } else { r };
}
fn rem_euc_assign(&mut self, rhs: i32) {
let r = self.0 % rhs;
self.0 = if r < 0 {
if rhs < 0 {
r - rhs
} else {
r + rhs
}
} else {
r
};
}
}
let mut rem_floor = I(-10);
rem_floor.rem_floor_assign(3);
assert_eq!(rem_floor.0, 2);
Required Methods§
sourcefn rem_trunc_assign(&mut self, rhs: Rhs)
fn rem_trunc_assign(&mut self, rhs: Rhs)
Finds the remainder when the quotient is rounded towards zero.
sourcefn rem_ceil_assign(&mut self, rhs: Rhs)
fn rem_ceil_assign(&mut self, rhs: Rhs)
Finds the remainder when the quotient is rounded up.
sourcefn rem_floor_assign(&mut self, rhs: Rhs)
fn rem_floor_assign(&mut self, rhs: Rhs)
Finds the remainder when the quotient is rounded down.
sourcefn rem_euc_assign(&mut self, rhs: Rhs)
fn rem_euc_assign(&mut self, rhs: Rhs)
Finds the positive remainder from Euclidean division.