From d4245b429796761a259d96e9f6f00d580be1d893 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 29 Oct 2018 08:48:21 +0100 Subject: compat/variance: don't use uintptr_t --- compat/variance.hpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'compat/variance.hpp') 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 -#include // 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; }; -- cgit v1.2.3