9template<
typename SampleType>
17 m_compensation ((SampleType) 0)
26 m_compensation = (SampleType) 0;
35 const SampleType corrected = value - m_compensation;
36 const SampleType newSum = m_sum + corrected;
37 m_compensation = (newSum - m_sum) - corrected;
49 template<
typename RequestedType>
50 RequestedType
get()
const
52 return static_cast<RequestedType> (m_sum);
62 SampleType m_compensation;
Implements Kahan algorithm for floating point accumulations.
RequestedType get() const
Value accumulated by the += operator, converted to the requested type.
AccurateSum(SampleType initialSum=(SampleType) 0)
Inits AccurateSum with a specific value.
SampleType getValue() const
AccurateSum & operator+=(SampleType value)
Adds a value to a sum, tracking the potential floating point error.
operator SampleType() const
Value accumulated by the += operator.
AccurateSum & operator=(SampleType initialSum)
Assigns AccurateSum's accumulated sum to a specific value.