Trait num::integer::Average [−][src]
Provides methods to compute the average of two integers, without overflows.
Required methods
pub 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);
pub 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);
Implementors
impl<I> Average for I where
I: Integer + Shr<usize, Output = I>,
&'a I: for<'a, 'b> BitAnd<&'b I>,
&'a I: for<'a, 'b> BitOr<&'b I>,
&'a I: for<'a, 'b> BitXor<&'b I>,
<&'a I as BitAnd<&'b I>>::Output == I,
<&'a I as BitOr<&'b I>>::Output == I,
<&'a I as BitXor<&'b I>>::Output == I,
[src]
I: Integer + Shr<usize, Output = I>,
&'a I: for<'a, 'b> BitAnd<&'b I>,
&'a I: for<'a, 'b> BitOr<&'b I>,
&'a I: for<'a, 'b> BitXor<&'b I>,
<&'a I as BitAnd<&'b I>>::Output == I,
<&'a I as BitOr<&'b I>>::Output == I,
<&'a I as BitXor<&'b I>>::Output == I,
pub fn average_floor(&self, other: &I) -> I
[src]
Returns the floor value of the average of self
and other
.
pub fn average_ceil(&self, other: &I) -> I
[src]
Returns the ceil value of the average of self
and other
.