pub trait AverageAssign<RHS = Self> {
// Required method
fn average_assign(&mut self, other: RHS);
}Expand description
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow: the result is always exact or within a half of the exact value, so it always fits in the same type as the inputs.
Required Methods§
fn average_assign(&mut self, other: RHS)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl AverageAssign for f32
impl AverageAssign for f32
Source§fn average_assign(&mut self, other: f32)
fn average_assign(&mut self, other: f32)
Computes the average (arithmetic mean) of two floating-point numbers, replacing the first number with it.
For finite values the result is the correctly rounded average: the nearest
representable value, with ties going to the value with the even mantissa. The
computation avoids intermediate overflow and underflow, so extreme values average
correctly. If either value is infinite or NaN, the result is whatever (x + y) / 2.0 produces.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for f64
impl AverageAssign for f64
Source§fn average_assign(&mut self, other: f64)
fn average_assign(&mut self, other: f64)
Computes the average (arithmetic mean) of two floating-point numbers, replacing the first number with it.
For finite values the result is the correctly rounded average: the nearest
representable value, with ties going to the value with the even mantissa. The
computation avoids intermediate overflow and underflow, so extreme values average
correctly. If either value is infinite or NaN, the result is whatever (x + y) / 2.0 produces.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for i8
impl AverageAssign for i8
Source§fn average_assign(&mut self, other: i8)
fn average_assign(&mut self, other: i8)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for i16
impl AverageAssign for i16
Source§fn average_assign(&mut self, other: i16)
fn average_assign(&mut self, other: i16)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for i32
impl AverageAssign for i32
Source§fn average_assign(&mut self, other: i32)
fn average_assign(&mut self, other: i32)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for i64
impl AverageAssign for i64
Source§fn average_assign(&mut self, other: i64)
fn average_assign(&mut self, other: i64)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for i128
impl AverageAssign for i128
Source§fn average_assign(&mut self, other: i128)
fn average_assign(&mut self, other: i128)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for isize
impl AverageAssign for isize
Source§fn average_assign(&mut self, other: isize)
fn average_assign(&mut self, other: isize)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for u8
impl AverageAssign for u8
Source§fn average_assign(&mut self, other: u8)
fn average_assign(&mut self, other: u8)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for u16
impl AverageAssign for u16
Source§fn average_assign(&mut self, other: u16)
fn average_assign(&mut self, other: u16)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for u32
impl AverageAssign for u32
Source§fn average_assign(&mut self, other: u32)
fn average_assign(&mut self, other: u32)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for u64
impl AverageAssign for u64
Source§fn average_assign(&mut self, other: u64)
fn average_assign(&mut self, other: u64)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for u128
impl AverageAssign for u128
Source§fn average_assign(&mut self, other: u128)
fn average_assign(&mut self, other: u128)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl AverageAssign for usize
impl AverageAssign for usize
Source§fn average_assign(&mut self, other: usize)
fn average_assign(&mut self, other: usize)
Computes the average (arithmetic mean) of two numbers, rounding to the nearest integer and replacing the first number with it. Two-way ties are broken by rounding to the even integer.
The average is computed without overflow; the result always fits in the same type as the inputs.
See the Average documentation for details.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.