Trait num::Integer [] [src]

pub trait Integer: Eq + Ord + PartialOrd<Self> + Num {
    fn div_floor(&self, other: &Self) -> Self;
fn mod_floor(&self, other: &Self) -> Self;
fn gcd(&self, other: &Self) -> Self;
fn lcm(&self, other: &Self) -> Self;
fn divides(&self, other: &Self) -> bool;
fn is_multiple_of(&self, other: &Self) -> bool;
fn is_even(&self) -> bool;
fn is_odd(&self) -> bool;
fn div_rem(&self, other: &Self) -> (Self, Self); fn div_mod_floor(&self, other: &Self) -> (Self, Self) { ... } }

Required Methods

Floored integer division.

Examples

assert!(( 8).div_floor(& 3) ==  2);
assert!(( 8).div_floor(&-3) == -3);
assert!((-8).div_floor(& 3) == -3);
assert!((-8).div_floor(&-3) ==  2);

assert!(( 1).div_floor(& 2) ==  0);
assert!(( 1).div_floor(&-2) == -1);
assert!((-1).div_floor(& 2) == -1);
assert!((-1).div_floor(&-2) ==  0);

Floored integer modulo, satisfying:

assert!(n.div_floor(&d) * d + n.mod_floor(&d) == n)

Examples

assert!(( 8).mod_floor(& 3) ==  2);
assert!(( 8).mod_floor(&-3) == -1);
assert!((-8).mod_floor(& 3) ==  1);
assert!((-8).mod_floor(&-3) == -2);

assert!(( 1).mod_floor(& 2) ==  1);
assert!(( 1).mod_floor(&-2) == -1);
assert!((-1).mod_floor(& 2) ==  1);
assert!((-1).mod_floor(&-2) == -1);

Greatest Common Divisor (GCD).

Examples

assert_eq!(6.gcd(&8), 2);
assert_eq!(7.gcd(&3), 1);

Lowest Common Multiple (LCM).

Examples

assert_eq!(7.lcm(&3), 21);
assert_eq!(2.lcm(&4), 4);

Deprecated, use is_multiple_of instead.

Returns true if self is a multiple of other.

Examples

assert_eq!(9.is_multiple_of(&3), true);
assert_eq!(3.is_multiple_of(&9), false);

Returns true if the number is even.

Examples

assert_eq!(3.is_even(), false);
assert_eq!(4.is_even(), true);

Returns true if the number is odd.

Examples

assert_eq!(3.is_odd(), true);
assert_eq!(4.is_odd(), false);

Simultaneous truncated integer division and modulus. Returns (quotient, remainder).

Examples

assert_eq!(( 8).div_rem( &3), ( 2,  2));
assert_eq!(( 8).div_rem(&-3), (-2,  2));
assert_eq!((-8).div_rem( &3), (-2, -2));
assert_eq!((-8).div_rem(&-3), ( 2, -2));

assert_eq!(( 1).div_rem( &2), ( 0,  1));
assert_eq!(( 1).div_rem(&-2), ( 0,  1));
assert_eq!((-1).div_rem( &2), ( 0, -1));
assert_eq!((-1).div_rem(&-2), ( 0, -1));

Provided Methods

Simultaneous floored integer division and modulus. Returns (quotient, remainder).

Examples

assert_eq!(( 8).div_mod_floor( &3), ( 2,  2));
assert_eq!(( 8).div_mod_floor(&-3), (-3, -1));
assert_eq!((-8).div_mod_floor( &3), (-3,  1));
assert_eq!((-8).div_mod_floor(&-3), ( 2, -2));

assert_eq!(( 1).div_mod_floor( &2), ( 0,  1));
assert_eq!(( 1).div_mod_floor(&-2), (-1, -1));
assert_eq!((-1).div_mod_floor( &2), (-1,  1));
assert_eq!((-1).div_mod_floor(&-2), ( 0, -1));

Implementations on Foreign Types

impl Integer for usize
[src]

[src]

Unsigned integer division. Returns the same result as div (/).

[src]

Unsigned integer modulo operation. Returns the same result as rem (%).

[src]

Calculates the Greatest Common Divisor (GCD) of the number and other

[src]

Calculates the Lowest Common Multiple (LCM) of the number and other.

[src]

Deprecated, use is_multiple_of instead.

[src]

Returns true if the number is a multiple of other.

[src]

Returns true if the number is divisible by 2.

[src]

Returns true if the number is not divisible by 2.

[src]

Simultaneous truncated integer division and modulus.

[src]

impl Integer for u16
[src]

[src]

Unsigned integer division. Returns the same result as div (/).

[src]

Unsigned integer modulo operation. Returns the same result as rem (%).

[src]

Calculates the Greatest Common Divisor (GCD) of the number and other

[src]

Calculates the Lowest Common Multiple (LCM) of the number and other.

[src]

Deprecated, use is_multiple_of instead.

[src]

Returns true if the number is a multiple of other.

[src]

Returns true if the number is divisible by 2.

[src]

Returns true if the number is not divisible by 2.

[src]

Simultaneous truncated integer division and modulus.

[src]

impl Integer for isize
[src]

[src]

Floored integer division

[src]

Floored integer modulo

[src]

Calculates div_floor and mod_floor simultaneously

[src]

Calculates the Greatest Common Divisor (GCD) of the number and other. The result is always positive.

[src]

Calculates the Lowest Common Multiple (LCM) of the number and other.

[src]

Deprecated, use is_multiple_of instead.

[src]

Returns true if the number is a multiple of other.

[src]

Returns true if the number is divisible by 2

[src]

Returns true if the number is not divisible by 2

[src]

Simultaneous truncated integer division and modulus.

impl Integer for i32
[src]

[src]

Floored integer division

[src]

Floored integer modulo

[src]

Calculates div_floor and mod_floor simultaneously

[src]

Calculates the Greatest Common Divisor (GCD) of the number and other. The result is always positive.

[src]

Calculates the Lowest Common Multiple (LCM) of the number and other.

[src]

Deprecated, use is_multiple_of instead.

[src]

Returns true if the number is a multiple of other.

[src]

Returns true if the number is divisible by 2

[src]

Returns true if the number is not divisible by 2

[src]

Simultaneous truncated integer division and modulus.

impl Integer for u8
[src]

[src]

Unsigned integer division. Returns the same result as div (/).

[src]

Unsigned integer modulo operation. Returns the same result as rem (%).

[src]

Calculates the Greatest Common Divisor (GCD) of the number and other

[src]

Calculates the Lowest Common Multiple (LCM) of the number and other.

[src]

Deprecated, use is_multiple_of instead.

[src]

Returns true if the number is a multiple of other.

[src]

Returns true if the number is divisible by 2.

[src]

Returns true if the number is not divisible by 2.

[src]

Simultaneous truncated integer division and modulus.

[src]

impl Integer for u32
[src]

[src]

Unsigned integer division. Returns the same result as div (/).

[src]

Unsigned integer modulo operation. Returns the same result as rem (%).

[src]

Calculates the Greatest Common Divisor (GCD) of the number and other

[src]

Calculates the Lowest Common Multiple (LCM) of the number and other.

[src]

Deprecated, use is_multiple_of instead.

[src]

Returns true if the number is a multiple of other.

[src]

Returns true if the number is divisible by 2.

[src]

Returns true if the number is not divisible by 2.

[src]

Simultaneous truncated integer division and modulus.

[src]

impl Integer for i8
[src]

[src]

Floored integer division

[src]

Floored integer modulo

[src]

Calculates div_floor and mod_floor simultaneously

[src]

Calculates the Greatest Common Divisor (GCD) of the number and other. The result is always positive.

[src]

Calculates the Lowest Common Multiple (LCM) of the number and other.

[src]

Deprecated, use is_multiple_of instead.

[src]

Returns true if the number is a multiple of other.

[src]

Returns true if the number is divisible by 2

[src]

Returns true if the number is not divisible by 2

[src]

Simultaneous truncated integer division and modulus.

impl Integer for i16
[src]

[src]

Floored integer division

[src]

Floored integer modulo

[src]

Calculates div_floor and mod_floor simultaneously

[src]

Calculates the Greatest Common Divisor (GCD) of the number and other. The result is always positive.

[src]

Calculates the Lowest Common Multiple (LCM) of the number and other.

[src]

Deprecated, use is_multiple_of instead.

[src]

Returns true if the number is a multiple of other.

[src]

Returns true if the number is divisible by 2

[src]

Returns true if the number is not divisible by 2

[src]

Simultaneous truncated integer division and modulus.

impl Integer for u64
[src]

[src]

Unsigned integer division. Returns the same result as div (/).

[src]

Unsigned integer modulo operation. Returns the same result as rem (%).

[src]

Calculates the Greatest Common Divisor (GCD) of the number and other

[src]

Calculates the Lowest Common Multiple (LCM) of the number and other.

[src]

Deprecated, use is_multiple_of instead.

[src]

Returns true if the number is a multiple of other.

[src]

Returns true if the number is divisible by 2.

[src]

Returns true if the number is not divisible by 2.

[src]

Simultaneous truncated integer division and modulus.

[src]

impl Integer for i64
[src]

[src]

Floored integer division

[src]

Floored integer modulo

[src]

Calculates div_floor and mod_floor simultaneously

[src]

Calculates the Greatest Common Divisor (GCD) of the number and other. The result is always positive.

[src]

Calculates the Lowest Common Multiple (LCM) of the number and other.

[src]

Deprecated, use is_multiple_of instead.

[src]

Returns true if the number is a multiple of other.

[src]

Returns true if the number is divisible by 2

[src]

Returns true if the number is not divisible by 2

[src]

Simultaneous truncated integer division and modulus.

Implementors