summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-10-29 08:48:21 +0100
committerStanislaw Halik <sthalik@misaki.pl>2018-10-29 08:25:57 +0000
commitd4245b429796761a259d96e9f6f00d580be1d893 (patch)
tree312824dfb6bf3df459c1023c2cd67c08bb7f3f3a /compat
parent523d7290148c17aadae0d2d3c7d9783f60419171 (diff)
compat/variance: don't use uintptr_t
Diffstat (limited to 'compat')
-rw-r--r--compat/variance.hpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/compat/variance.hpp b/compat/variance.hpp
index 237bb51a..8abefd33 100644
--- a/compat/variance.hpp
+++ b/compat/variance.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <cmath>
-#include <cinttypes>
// no copyright information other than the attribution below.
@@ -18,18 +17,18 @@
// Comparison of Several Algorithms for Computing Sample Means and Variances.
// Journal of the American Statistical Association, Vol. 69, No. 348, 859-866.
-class variance final
+struct variance final
{
- double m_old, m_new, s_old, s_new;
- std::uintptr_t cnt = 0;
-
-public:
- using size_type = std::uintptr_t;
+ using size_type = unsigned;
variance& operator=(variance const&) = default;
- void clear() { *this = variance(); }
+ void clear() { *this = {}; }
+
+ constexpr size_type count() const { return cnt; }
- size_type count() { return cnt; }
+ constexpr double avg() const { return cnt > 0 ? m_new : 0; }
+ constexpr double Var() const { return cnt > 1 ? s_new/(cnt - 1) : 0; }
+ double stddev() const { return std::sqrt(Var()); }
void input(double x)
{
@@ -50,7 +49,7 @@ public:
}
}
- double avg() const { return cnt > 0 ? m_new : 0; }
- double Var() const { return cnt > 1 ? s_new/(cnt - 1) : 0; }
- double stddev() const { return std::sqrt(Var()); }
+private:
+ double m_old, m_new, s_old, s_new;
+ size_type cnt = 0;
};