Add a reference
This commit is contained in:
parent
2b6aa2e37e
commit
b5f542d4a9
@ -39,6 +39,7 @@ impl Average {
|
|||||||
|
|
||||||
/// Add a number to the sequence of which the average is calculated.
|
/// Add a number to the sequence of which the average is calculated.
|
||||||
pub fn add(&mut self, x: f64) {
|
pub fn add(&mut self, x: f64) {
|
||||||
|
// See https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance.
|
||||||
self.n += 1;
|
self.n += 1;
|
||||||
let delta = x - self.avg;
|
let delta = x - self.avg;
|
||||||
self.avg += delta / f64::approx_from(self.n).unwrap();
|
self.avg += delta / f64::approx_from(self.n).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user