WaveBlocksND
|
The Kahan's algorithm achieves O(1) error growth for summing N numbers. More...
#include <kahan_sum.hpp>
Public Member Functions | |
KahanSum ()=default | |
compiler-generated default constructor More... | |
KahanSum (const T &zero) | |
A zero initializing constructor for types that cannot provide a default constructor. More... | |
KahanSum (const KahanSum< T > &that)=default | |
compiler-generated copy constructor More... | |
KahanSum & | operator= (const KahanSum< T > &that)=default |
compiler-generated copy assignment operator More... | |
KahanSum & | operator+= (const T &summand) |
adds a number More... | |
const T & | operator() () const |
retrieves accumulated sum. More... | |
Private Attributes | |
T | sum_ |
T | c_ |
T | y_ |
T | t_ |
The Kahan's algorithm achieves O(1) error growth for summing N numbers.
This implementation works for every type that satisfies following requirements:
T | type of summands |
|
default |
compiler-generated default constructor
Be aware that this constructor fails on summand types that cannot provide a default constructor like dynamically sized arrays/matrices.
|
inline |
A zero initializing constructor for types that cannot provide a default constructor.
A noteable example is a dynamically sized matrix.
[in] | zero | initialized zero value as a template |
|
default |
compiler-generated copy constructor
|
inline |
retrieves accumulated sum.
|
inline |
adds a number
[in] | summand | summand |
|
default |
compiler-generated copy assignment operator
|
private |
A running compensation for lost low-order bits.
|
private |
Accumulated sum.
|
private |
|
private |
Preallocated temporary variables