37 template <
typename FloatType>
51 jassert (juce_isfinite (v));
57 if (v > maximum) maximum = v;
58 if (v < minimum) minimum = v;
72 return count > 0 ? sum / (FloatType) count
81 return count > 0 ? (sumSquares - sum * sum / (FloatType) count) / (FloatType) count
119 KahanSum() =
default;
120 operator FloatType() const noexcept {
return sum; }
122 void JUCE_NO_ASSOCIATIVE_MATH_OPTIMISATIONS operator+= (FloatType value) noexcept
124 FloatType correctedValue = value - error;
125 FloatType newSum = sum + correctedValue;
126 error = (newSum - sum) - correctedValue;
130 FloatType sum{}, error{};
135 KahanSum sum, sumSquares;
136 FloatType minimum { std::numeric_limits<FloatType>::infinity() },
137 maximum { -std::numeric_limits<FloatType>::infinity() };
A class that measures various statistics about a series of floating point values that it is given.
StatisticsAccumulator()=default
Constructs a new StatisticsAccumulator.
FloatType getMinValue() const noexcept
Returns the smallest of all previously added values.
FloatType getAverage() const noexcept
Returns the average (arithmetic mean) of all previously added values.
void reset() noexcept
Reset the accumulator.
FloatType getVariance() const noexcept
Returns the variance of all previously added values.
size_t getCount() const noexcept
Returns how many values have been added to this accumulator.
void addValue(FloatType v) noexcept
Add a new value to the accumulator.
FloatType getStandardDeviation() const noexcept
Returns the standard deviation of all previously added values.
FloatType getMaxValue() const noexcept
Returns the largest of all previously added values.