# Trait num_integer::Integer [−] [src]

    pub trait Integer: Sized + Num + PartialOrd + Ord + Eq {
        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

### `fn div_floor(&self, other: &Self) -> Self`

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);Run

### `fn mod_floor(&self, other: &Self) -> Self`

Floored integer modulo, satisfying:

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

# 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);Run

### `fn gcd(&self, other: &Self) -> Self`

Greatest Common Divisor (GCD).

# Examples

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

### `fn lcm(&self, other: &Self) -> Self`

Lowest Common Multiple (LCM).

# Examples

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

### `fn divides(&self, other: &Self) -> bool`

Deprecated, use `is_multiple_of` instead.

### `fn is_multiple_of(&self, other: &Self) -> bool`

Returns `true` if `other` is a multiple of `self`.

# Examples

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

### `fn is_even(&self) -> bool`

Returns `true` if the number is even.

# Examples

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

### `fn is_odd(&self) -> bool`

Returns `true` if the number is odd.

# Examples

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

### `fn div_rem(&self, other: &Self) -> (Self, Self)`

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));Run

## Provided Methods

### `fn div_mod_floor(&self, other: &Self) -> (Self, Self)`

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));Run

## Implementors

- `impl Integer for i8`
- `impl Integer for i16`
- `impl Integer for i32`
- `impl Integer for i64`
- `impl Integer for isize`
- `impl Integer for u8`
- `impl Integer for u16`
- `impl Integer for u32`
- `impl Integer for u64`
- `impl Integer for usize`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)