OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::util::KahanSummator< T > Class Template Reference

Accurate summation of floating point numbers with the Kahan algorithm Reduces round-off effects which arise if the total sum is significantly larger than the single summands. More...

#include <calc.h>

+ Collaboration diagram for olb::util::KahanSummator< T >:

Public Member Functions

void add (T summand)
 
getSum () const
 
void initialize (T value=0.)
 

Detailed Description

template<typename T>
class olb::util::KahanSummator< T >

Accurate summation of floating point numbers with the Kahan algorithm Reduces round-off effects which arise if the total sum is significantly larger than the single summands.

Works very well for adding many numbers of the same sign. Does not really help if sign changes, e.g. if the summands are randomly distributed around 0. Cf. https://en.wikipedia.org/wiki/Kahan_summation_algorithm

Definition at line 57 of file calc.h.

Member Function Documentation

◆ add()

template<typename T >
void olb::util::KahanSummator< T >::add ( T summand)
inline

Definition at line 64 of file calc.h.

64 {
65 const T y {summand - c};
66 const T t {sum + y};
67 c = (t - sum) - y;
68 sum = t;
69 }
platform_constant Fraction t[Q]

◆ getSum()

template<typename T >
T olb::util::KahanSummator< T >::getSum ( ) const
inline

Definition at line 71 of file calc.h.

71 {
72 return sum;
73 }

◆ initialize()

template<typename T >
void olb::util::KahanSummator< T >::initialize ( T value = 0.)
inline

Definition at line 75 of file calc.h.

75 {
76 sum = value;
77 c = T(0);
78 }
typename std::integral_constant< TYPE, VALUE >::type value
Identity type to wrap non-type template arguments.
Definition meta.h:96

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