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

    pub trait Average: Integer {
        fn average_ceil(&self, other: &Self) -> Self;
        fn average_floor(&self, other: &Self) -> Self;
    }

Provides methods to compute the average of two integers, without overflows.

## Required methods

### `fn average_ceil(&self, other: &Self) -> Self` [src]

Returns the ceiling value of the average of `self` and `other`. – `⌈(self + other)/2⌉`

# Examples

    use num_integer::Average;

    assert_eq!(( 3).average_ceil(&10),  7);
    assert_eq!((-2).average_ceil(&-5), -3);
    assert_eq!(( 4).average_ceil(& 4),  4);

    assert_eq!(u8::max_value().average_ceil(&2), 129);
    assert_eq!(i8::min_value().average_ceil(&-1), -64);
    assert_eq!(i8::min_value().average_ceil(&i8::max_value()), 0);

### `fn average_floor(&self, other: &Self) -> Self` [src]

Returns the floor value of the average of `self` and `other`. – `⌊(self + other)/2⌋`

# Examples

    use num_integer::Average;

    assert_eq!(( 3).average_floor(&10),  6);
    assert_eq!((-2).average_floor(&-5), -4);
    assert_eq!(( 4).average_floor(& 4),  4);

    assert_eq!(u8::max_value().average_floor(&2), 128);
    assert_eq!(i8::min_value().average_floor(&-1), -65);
    assert_eq!(i8::min_value().average_floor(&i8::max_value()), -1);

Loading content...

## Implementors

### `impl<I> Average for I where
I: Integer + Shr<usize, Output = I>,
&'a I: BitAnd<&'b I, Output = I> + BitOr<&'b I, Output = I> + BitXor<&'b I, Output = I>,` [src]

#### `fn average_floor(&self, other: &I) -> I` [src]

Returns the floor value of the average of `self` and `other`.

#### `fn average_ceil(&self, other: &I) -> I` [src]

Returns the ceil value of the average of `self` and `other`.

Loading content...