ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::NeumaierSum< T > Class Template Reference

a sum of values of T that follows additions and subtractions, with the compensation of Neumaier when T is floating and it is asked: the error after \( k \) terms is then of the order of \( \varepsilon \) times the sum of their absolute values, instead of \( k \varepsilon \) times More...

#include <ADS/Modification.h>

Public member functions

 NeumaierSum (bool compensated=false)
 the sum \( 0 \), compensated if compensated
void add (const T &x)
 adds \( x \)
void sub (const T &x)
 subtracts \( x \)
T value (void) const
 the sum
void reset (const T &x=T())
 the sum set to \( x \), with no compensation
void compensate (bool on)
 compensated or not from now on
bool compensated (void) const
 whether the sum is compensated

Detailed description

template<class T>
class ADS::NeumaierSum< T >

a sum of values of T that follows additions and subtractions, with the compensation of Neumaier when T is floating and it is asked: the error after \( k \) terms is then of the order of \( \varepsilon \) times the sum of their absolute values, instead of \( k \varepsilon \) times

In pseudocode (beyond the book), \( s \) the sum and \( c \) the compensation, the value \( s + c \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{add}( x ) \cr 2 & \quad t \gets s + x \cr 3 & \quad \textbf{if}\ | s | \ge | x |\ \textbf{then}\ c \gets c + ( ( s - t ) + x )\ \textbf{else}\ c \gets c + ( ( x - t ) + s ) \cr 4 & \quad s \gets t \end{array}} \]

Constructor and destructor documentation

◆ NeumaierSum()

template<class T>
ADS::NeumaierSum< T >::NeumaierSum ( bool compensated = false)
inlineexplicit

the sum \( 0 \), compensated if compensated

Member function documentation

◆ add()

template<class T>
void ADS::NeumaierSum< T >::add ( const T & x)
inline

adds \( x \)

◆ compensate()

template<class T>
void ADS::NeumaierSum< T >::compensate ( bool on)
inline

compensated or not from now on

◆ compensated()

template<class T>
bool ADS::NeumaierSum< T >::compensated ( void ) const
inlinenodiscard

whether the sum is compensated

◆ reset()

template<class T>
void ADS::NeumaierSum< T >::reset ( const T & x = T())
inline

the sum set to \( x \), with no compensation

◆ sub()

template<class T>
void ADS::NeumaierSum< T >::sub ( const T & x)
inline

subtracts \( x \)

◆ value()

template<class T>
T ADS::NeumaierSum< T >::value ( void ) const
inlinenodiscard

the sum


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