WaveBlocksND
Public Member Functions | Private Attributes | List of all members
waveblocks::math::KahanSum< T > Class Template Reference

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...
 
KahanSumoperator= (const KahanSum< T > &that)=default
 compiler-generated copy assignment operator More...
 
KahanSumoperator+= (const T &summand)
 adds a number More...
 
const T & operator() () const
 retrieves accumulated sum. More...
 

Private Attributes

sum_
 
c_
 
y_
 
t_
 

Detailed Description

template<class T>
class waveblocks::math::KahanSum< T >

The Kahan's algorithm achieves O(1) error growth for summing N numbers.

This implementation works for every type that satisfies following requirements:

Template Parameters
Ttype of summands

Constructor & Destructor Documentation

template<class T>
waveblocks::math::KahanSum< T >::KahanSum ( )
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.

See also
KahanSum::KahanSum(const T&)
template<class T>
waveblocks::math::KahanSum< T >::KahanSum ( const T &  zero)
inline

A zero initializing constructor for types that cannot provide a default constructor.

A noteable example is a dynamically sized matrix.

Parameters
[in]zeroinitialized zero value as a template
template<class T>
waveblocks::math::KahanSum< T >::KahanSum ( const KahanSum< T > &  that)
default

compiler-generated copy constructor

Member Function Documentation

template<class T>
const T& waveblocks::math::KahanSum< T >::operator() ( ) const
inline

retrieves accumulated sum.

Returns
accumulated sum
template<class T>
KahanSum& waveblocks::math::KahanSum< T >::operator+= ( const T &  summand)
inline

adds a number

Parameters
[in]summandsummand
template<class T>
KahanSum& waveblocks::math::KahanSum< T >::operator= ( const KahanSum< T > &  that)
default

compiler-generated copy assignment operator

Member Data Documentation

template<class T>
T waveblocks::math::KahanSum< T >::c_
private

A running compensation for lost low-order bits.

template<class T>
T waveblocks::math::KahanSum< T >::sum_
private

Accumulated sum.

template<class T>
T waveblocks::math::KahanSum< T >::t_
private
template<class T>
T waveblocks::math::KahanSum< T >::y_
private

Preallocated temporary variables


The documentation for this class was generated from the following file: