Trait rug::ops::RemRounding [−][src]
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
Loading content...Required methods
fn rem_trunc(self, rhs: Rhs) -> Self::Output
[src]
Finds the remainder when the quotient is rounded towards zero.
fn rem_ceil(self, rhs: Rhs) -> Self::Output
[src]
Finds the remainder when the quotient is rounded up.
fn rem_floor(self, rhs: Rhs) -> Self::Output
[src]
Finds the remainder when the quotient is rounded down.
fn rem_euc(self, rhs: Rhs) -> Self::Output
[src]
Finds the positive remainder from Euclidean division.