Trait rug::ops::RemRounding
[−]
[src]
pub trait RemRounding<Rhs = Self> { type Output; fn rem_trunc(self, rhs: Rhs) -> Self::Output; fn rem_ceil(self, rhs: Rhs) -> Self::Output; fn rem_floor(self, rhs: Rhs) -> Self::Output; fn rem_euc(self, rhs: Rhs) -> Self::Output; }
Rounding variants of the remainder operation.
Examples
use rug::ops::RemRounding; struct I(i32); impl RemRounding<i32> for I { type Output = i32; fn rem_trunc(self, rhs: i32) -> i32 { self.0 % rhs } fn rem_ceil(self, rhs: i32) -> i32 { let r = self.0 % rhs; let change = if rhs > 0 { r > 0 } else { r < 0 }; if change { r - rhs } else { r } } fn rem_floor(self, rhs: i32) -> i32 { let r = self.0 % rhs; let change = if rhs > 0 { r < 0 } else { r > 0 }; if change { r + rhs } else { r } } fn rem_euc(self, rhs: i32) -> i32 { let r = self.0 % rhs; if r < 0 { if rhs < 0 { r - rhs } else { r + rhs } } else { r } } } assert_eq!(I(-10).rem_trunc(-3), -1); assert_eq!(I(-10).rem_ceil(-3), 2); assert_eq!(I(-10).rem_floor(-3), -1); assert_eq!(I(-10).rem_euc(-3), 2);
Associated Types
type Output
The resulting type from the remainder operation.
Required Methods
fn rem_trunc(self, rhs: Rhs) -> Self::Output
Finds the remainder when the quotient is rounded towards zero.
fn rem_ceil(self, rhs: Rhs) -> Self::Output
Finds the remainder when the quotient is rounded up.
fn rem_floor(self, rhs: Rhs) -> Self::Output
Finds the remainder when the quotient is rounded down.
fn rem_euc(self, rhs: Rhs) -> Self::Output
Finds the positive remainder from Euclidean division.
Implementations on Foreign Types
impl RemRounding for i8
[src]
impl RemRounding for i16
[src]
impl RemRounding for i32
[src]
impl RemRounding for i64
[src]
impl RemRounding for isize
[src]
impl RemRounding<Integer> for i32
[src]
impl<'a> RemRounding<&'a Integer> for i32
[src]
type Output = RemRoundingFromRefI32<'a>
fn rem_trunc(self, rhs: &'a Integer) -> RemRoundingFromRefI32<'a>
[src]
fn rem_ceil(self, rhs: &'a Integer) -> RemRoundingFromRefI32<'a>
[src]
fn rem_floor(self, rhs: &'a Integer) -> RemRoundingFromRefI32<'a>
[src]
fn rem_euc(self, rhs: &'a Integer) -> RemRoundingFromRefI32<'a>
[src]
impl RemRounding<Integer> for u32
[src]
impl<'a> RemRounding<&'a Integer> for u32
[src]
type Output = RemRoundingFromRefU32<'a>
fn rem_trunc(self, rhs: &'a Integer) -> RemRoundingFromRefU32<'a>
[src]
fn rem_ceil(self, rhs: &'a Integer) -> RemRoundingFromRefU32<'a>
[src]
fn rem_floor(self, rhs: &'a Integer) -> RemRoundingFromRefU32<'a>
[src]
fn rem_euc(self, rhs: &'a Integer) -> RemRoundingFromRefU32<'a>
[src]
Implementors
impl RemRounding<Integer> for Integer type Output = Integer;
impl<'a> RemRounding<&'a Integer> for Integer type Output = Integer;
impl<'a> RemRounding<Integer> for &'a Integer type Output = Integer;
impl<'a> RemRounding<&'a Integer> for &'a Integer type Output = RemRoundingRef<'a>;
impl RemRounding<i32> for Integer type Output = Integer;
impl<'a> RemRounding<i32> for &'a Integer type Output = RemRoundingRefI32<'a>;
impl RemRounding<u32> for Integer type Output = Integer;
impl<'a> RemRounding<u32> for &'a Integer type Output = RemRoundingRefU32<'a>;