Add a reference

This commit is contained in:
Vinzent Steinberg 2017-05-05 14:18:09 +02:00
parent 2b6aa2e37e
commit b5f542d4a9

View File

@ -39,6 +39,7 @@ impl Average {
/// Add a number to the sequence of which the average is calculated.
pub fn add(&mut self, x: f64) {
// See https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance.
self.n += 1;
let delta = x - self.avg;
self.avg += delta / f64::approx_from(self.n).unwrap();