Trait rug::ops::DivRounding
[−]
[src]
pub trait DivRounding<Rhs = Self> { type Output; fn div_trunc(self, rhs: Rhs) -> Self::Output; fn div_ceil(self, rhs: Rhs) -> Self::Output; fn div_floor(self, rhs: Rhs) -> Self::Output; fn div_euc(self, rhs: Rhs) -> Self::Output; }
Rounding variants of division.
Examples
use rug::ops::DivRounding; struct I(i32); impl DivRounding<i32> for I { type Output = i32; fn div_trunc(self, rhs: i32) -> i32 { self.0 / rhs } fn div_ceil(self, rhs: i32) -> i32 { let (q, r) = (self.0 / rhs, self.0 % rhs); let change = if rhs > 0 { r > 0 } else { r < 0 }; if change { q + 1 } else { q } } fn div_floor(self, rhs: i32) -> i32 { let (q, r) = (self.0 / rhs, self.0 % rhs); let change = if rhs > 0 { r < 0 } else { r > 0 }; if change { q - 1 } else { q } } fn div_euc(self, rhs: i32) -> i32 { let (q, r) = (self.0 / rhs, self.0 % rhs); if r < 0 { if rhs < 0 { q + 1 } else { q - 1 } } else { q } } } assert_eq!(I(-10).div_trunc(-3), 3); assert_eq!(I(-10).div_ceil(-3), 4); assert_eq!(I(-10).div_floor(-3), 3); assert_eq!(I(-10).div_euc(-3), 4);
Associated Types
type Output
The resulting type from the division operation.
Required Methods
fn div_trunc(self, rhs: Rhs) -> Self::Output
Performs division, rounding the quotient towards zero.
fn div_ceil(self, rhs: Rhs) -> Self::Output
Performs division, rounding the quotient up.
fn div_floor(self, rhs: Rhs) -> Self::Output
Performs division, rounding the quotient down.
fn div_euc(self, rhs: Rhs) -> Self::Output
Performs Euclidean division, rounding the quotient so that the remainder cannot be negative.
Implementations on Foreign Types
impl DivRounding for i8
[src]
impl DivRounding for i16
[src]
impl DivRounding for i32
[src]
impl DivRounding for i64
[src]
impl DivRounding for isize
[src]
impl DivRounding<Integer> for i32
[src]
impl<'a> DivRounding<&'a Integer> for i32
[src]
type Output = DivRoundingFromRefI32<'a>
fn div_trunc(self, rhs: &'a Integer) -> DivRoundingFromRefI32<'a>
[src]
fn div_ceil(self, rhs: &'a Integer) -> DivRoundingFromRefI32<'a>
[src]
fn div_floor(self, rhs: &'a Integer) -> DivRoundingFromRefI32<'a>
[src]
fn div_euc(self, rhs: &'a Integer) -> DivRoundingFromRefI32<'a>
[src]
impl DivRounding<Integer> for u32
[src]
impl<'a> DivRounding<&'a Integer> for u32
[src]
type Output = DivRoundingFromRefU32<'a>
fn div_trunc(self, rhs: &'a Integer) -> DivRoundingFromRefU32<'a>
[src]
fn div_ceil(self, rhs: &'a Integer) -> DivRoundingFromRefU32<'a>
[src]
fn div_floor(self, rhs: &'a Integer) -> DivRoundingFromRefU32<'a>
[src]
fn div_euc(self, rhs: &'a Integer) -> DivRoundingFromRefU32<'a>
[src]
Implementors
impl DivRounding<Integer> for Integer type Output = Integer;
impl<'a> DivRounding<&'a Integer> for Integer type Output = Integer;
impl<'a> DivRounding<Integer> for &'a Integer type Output = Integer;
impl<'a> DivRounding<&'a Integer> for &'a Integer type Output = DivRoundingRef<'a>;
impl DivRounding<i32> for Integer type Output = Integer;
impl<'a> DivRounding<i32> for &'a Integer type Output = DivRoundingRefI32<'a>;
impl DivRounding<u32> for Integer type Output = Integer;
impl<'a> DivRounding<u32> for &'a Integer type Output = DivRoundingRefU32<'a>;