Trait rug::ops::DivRoundingAssign [−][src]
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
fn div_trunc_assign(&mut self, rhs: Rhs)
[src]
Performs division, rounding the quotient towards zero.
fn div_ceil_assign(&mut self, rhs: Rhs)
[src]
Performs division, rounding the quotient up.
fn div_floor_assign(&mut self, rhs: Rhs)
[src]
Performs division, rounding the quotient down.
fn div_euc_assign(&mut self, rhs: Rhs)
[src]
Performs Euclidean division, rounding the quotient so that the remainder cannot be negative.