This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/math/stats/Average.h
kazu 51c0945e12 statistic helper classes
test-cases
modified grid importance for better trap-detection
2016-10-01 13:17:14 +02:00

44 lines
567 B
C++

#ifndef AVERAGE_H
#define AVERAGE_H
#include "../../Assertions.h"
namespace Stats {
template <typename Scalar> class Average {
private:
int cnt;
Scalar sum;
public:
/** ctor */
Average() : cnt(0), sum(0) {
;
}
/** contains a valid average? */
bool isValid() const {
return cnt > 0;
}
/** add a new value */
void add(const Scalar val) {
sum += val;
++cnt;
}
/** get the current value */
Scalar get() const {
Assert::isNot0(cnt, "add() values first!");
return sum / (Scalar)cnt;
}
};
}
#endif // AVERAGE_H