Trait Integer
trait Integer: Sized + Num + PartialOrd + Ord + Eq
Required Methods
fn div_floor(self: &Self, other: &Self) -> SelfFloored integer division.
Examples
# use Integer; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!;fn mod_floor(self: &Self, other: &Self) -> SelfFloored integer modulo, satisfying:
# use Integer; # let n = 1; let d = 1; assert!Examples
# use Integer; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!;fn gcd(self: &Self, other: &Self) -> SelfGreatest Common Divisor (GCD).
Examples
# use Integer; assert_eq!; assert_eq!;fn lcm(self: &Self, other: &Self) -> SelfLowest Common Multiple (LCM).
Examples
# use Integer; assert_eq!; assert_eq!; assert_eq!;fn is_multiple_of(self: &Self, other: &Self) -> boolReturns
trueifselfis a multiple ofother.Examples
# use Integer; assert_eq!; assert_eq!;fn is_even(self: &Self) -> boolReturns
trueif the number is even.Examples
# use Integer; assert_eq!; assert_eq!;fn is_odd(self: &Self) -> boolReturns
trueif the number is odd.Examples
# use Integer; assert_eq!; assert_eq!;fn div_rem(self: &Self, other: &Self) -> (Self, Self)Simultaneous truncated integer division and modulus. Returns
(quotient, remainder).Examples
# use Integer; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;
Provided Methods
fn div_ceil(self: &Self, other: &Self) -> SelfCeiled integer division.
Examples
# use Integer; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;fn gcd_lcm(self: &Self, other: &Self) -> (Self, Self)Greatest Common Divisor (GCD) and Lowest Common Multiple (LCM) together.
Potentially more efficient than calling
gcdandlcmindividually for identical inputs.Examples
# use Integer; assert_eq!; assert_eq!;fn extended_gcd(self: &Self, other: &Self) -> ExtendedGcd<Self> where Self: CloneGreatest common divisor and Bézout coefficients.
Examples
#fn extended_gcd_lcm(self: &Self, other: &Self) -> (ExtendedGcd<Self>, Self) where Self: Clone + SignedGreatest common divisor, least common multiple, and Bézout coefficients.
fn divides(self: &Self, other: &Self) -> boolDeprecated, use
is_multiple_ofinstead.fn div_mod_floor(self: &Self, other: &Self) -> (Self, Self)Simultaneous floored integer division and modulus. Returns
(quotient, remainder).Examples
# use Integer; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;fn next_multiple_of(self: &Self, other: &Self) -> Self where Self: CloneRounds up to nearest multiple of argument.
Notes
For signed types,
a.next_multiple_of(b) = a.prev_multiple_of(b.neg()).Examples
# use Integer; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;fn prev_multiple_of(self: &Self, other: &Self) -> Self where Self: CloneRounds down to nearest multiple of argument.
Notes
For signed types,
a.prev_multiple_of(b) = a.next_multiple_of(b.neg()).Examples
# use Integer; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;fn dec(self: &mut Self) where Self: CloneDecrements self by one.
Examples
# use Integer; let mut x: i32 = 43; x.dec; assert_eq!;fn inc(self: &mut Self) where Self: CloneIncrements self by one.
Examples
# use Integer; let mut x: i32 = 41; x.inc; assert_eq!;
Implementors
impl Integer for u32impl Integer for u64impl Integer for u128impl Integer for usizeimpl Integer for i8impl Integer for i16impl Integer for i32impl Integer for i64impl Integer for i128impl Integer for isizeimpl Integer for u8impl Integer for u16