A repository where I'll put experiments learning, proving or disproving things about C++. These experiments will feature measurements, use Tracy to show behavior, and generally have the goal of simplifying normal C++ usage.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
c-plus-plus-dafuq/stats.hpp

46 lines
625 B

#pragma once
#include <cmath>
struct Stats {
double sum = 0.0;
double sumsq = 0.0;
unsigned long n = 0L;
double min = 0.0;
double max = 0.0;
inline void reset() {
sum = 0;
sumsq = 0;
n = 0L;
min = 0;
max = 0;
}
inline double mean() {
return sum / n;
}
inline double stddev() {
return std::sqrt((sumsq - (sum * sum / n)) /
(n - 1));
}
inline void sample(double s) {
sum += s;
sumsq += s * s;
if (n == 0) {
min = s;
max = s;
} else {
if (min > s) min = s;
if (max < s) max = s;
}
n += 1;
}
void dump();
};