|
ADS
Algorithms and Data Structures
|
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 | |
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}} \]
|
inlineexplicit |
the sum \( 0 \), compensated if compensated
|
inline |
adds \( x \)
|
inline |
compensated or not from now on
|
inlinenodiscard |
whether the sum is compensated
|
inline |
the sum set to \( x \), with no compensation
|
inline |
subtracts \( x \)
|
inlinenodiscard |
the sum