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<'a> DivRounding<&'a i8> for i8
[src]
impl DivRounding for i16
[src]
impl<'a> DivRounding<&'a i16> for i16
[src]
impl DivRounding for i32
[src]
impl<'a> DivRounding<&'a i32> for i32
[src]
impl DivRounding for i64
[src]
impl<'a> DivRounding<&'a i64> for i64
[src]
impl DivRounding for isize
[src]
impl<'a> DivRounding<&'a isize> for isize
[src]
impl DivRounding<Integer> for i32
[src]
impl<'i> DivRounding<&'i Integer> for i32
[src]
type Output = DivRoundingFromRefI32<'i>
fn div_trunc(self, rhs: &'i Integer) -> DivRoundingFromRefI32<'i>
[src]
fn div_ceil(self, rhs: &'i Integer) -> DivRoundingFromRefI32<'i>
[src]
fn div_floor(self, rhs: &'i Integer) -> DivRoundingFromRefI32<'i>
[src]
fn div_euc(self, rhs: &'i Integer) -> DivRoundingFromRefI32<'i>
[src]
impl<'t> DivRounding<Integer> for &'t i32
[src]
impl<'i, 't> DivRounding<&'i Integer> for &'t i32
[src]
type Output = DivRoundingFromRefI32<'i>
fn div_trunc(self, rhs: &'i Integer) -> DivRoundingFromRefI32<'i>
[src]
fn div_ceil(self, rhs: &'i Integer) -> DivRoundingFromRefI32<'i>
[src]
fn div_floor(self, rhs: &'i Integer) -> DivRoundingFromRefI32<'i>
[src]
fn div_euc(self, rhs: &'i Integer) -> DivRoundingFromRefI32<'i>
[src]
impl DivRounding<Integer> for u32
[src]
impl<'i> DivRounding<&'i Integer> for u32
[src]
type Output = DivRoundingFromRefU32<'i>
fn div_trunc(self, rhs: &'i Integer) -> DivRoundingFromRefU32<'i>
[src]
fn div_ceil(self, rhs: &'i Integer) -> DivRoundingFromRefU32<'i>
[src]
fn div_floor(self, rhs: &'i Integer) -> DivRoundingFromRefU32<'i>
[src]
fn div_euc(self, rhs: &'i Integer) -> DivRoundingFromRefU32<'i>
[src]
impl<'t> DivRounding<Integer> for &'t u32
[src]
impl<'i, 't> DivRounding<&'i Integer> for &'t u32
[src]
type Output = DivRoundingFromRefU32<'i>
fn div_trunc(self, rhs: &'i Integer) -> DivRoundingFromRefU32<'i>
[src]
fn div_ceil(self, rhs: &'i Integer) -> DivRoundingFromRefU32<'i>
[src]
fn div_floor(self, rhs: &'i Integer) -> DivRoundingFromRefU32<'i>
[src]
fn div_euc(self, rhs: &'i Integer) -> DivRoundingFromRefU32<'i>
[src]
Implementors
impl DivRounding for Integer type Output = Integer;
impl<'i> DivRounding<&'i Integer> for Integer type Output = Integer;
impl<'i> DivRounding<Integer> for &'i Integer type Output = Integer;
impl<'i> DivRounding for &'i Integer type Output = DivRoundingRef<'i>;
impl DivRounding<i32> for Integer type Output = Integer;
impl<'t> DivRounding<&'t i32> for Integer type Output = Integer;
impl<'i> DivRounding<i32> for &'i Integer type Output = DivRoundingRefI32<'i>;
impl<'t, 'i> DivRounding<&'t i32> for &'i Integer type Output = DivRoundingRefI32<'i>;
impl DivRounding<u32> for Integer type Output = Integer;
impl<'t> DivRounding<&'t u32> for Integer type Output = Integer;
impl<'i> DivRounding<u32> for &'i Integer type Output = DivRoundingRefU32<'i>;
impl<'t, 'i> DivRounding<&'t u32> for &'i Integer type Output = DivRoundingRefU32<'i>;