8ee0d003a2ea83012af6957bcaa9a9e45c957b7b
[junction.git] / junction / Averager.cpp
1 /*------------------------------------------------------------------------
2   Junction: Concurrent data structures in C++
3   Copyright (c) 2016 Jeff Preshing
4
5   Distributed under the Simplified BSD License.
6   Original location: https://github.com/preshing/junction
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the LICENSE file for more information.
11 ------------------------------------------------------------------------*/
12
13 #include <junction/Core.h>
14 #include <junction/Averager.h>
15 #include <math.h>
16
17 namespace junction {
18
19 double Averager::getStdDev() {
20     finalize();
21     double avg = getAverage();
22     double dev = 0;
23     for (ureg i = 0; i < m_values.size(); i++) {
24         double diff = m_values[i] - avg;
25         dev += diff * diff;
26     }
27     return sqrt(dev / m_values.size());
28 }
29
30 } // namespace junction