Logo ROOT   6.13/01
Reference Guide
List of all members | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
ROOT::Math::KahanSum< T > Class Template Reference

template<class T>
class ROOT::Math::KahanSum< T >

The Kahan compensate summation algorithm significantly reduces the numerical error in the total obtained by adding a sequence of finite precision floating point numbers.

This is done by keeping a separate running compensation (a variable to accumulate small errors).
The intial values of the result and the correction are set to the default value of the type it hass been instantiated with.
####Examples:

std::vector<double> numbers = {0.01, 0.001, 0.0001, 0.000001, 0.00000000001};
k.Add(numbers);

Definition at line 85 of file Util.h.

Public Member Functions

 KahanSum (const T &initialValue=T{})
 Constructor accepting a initial value for the summation as parameter. More...
 
void Add (const T &x)
 Single element accumulated addition. More...
 
template<class Iterator >
void Add (const Iterator begin, const Iterator end)
 Iterate over a datastructure referenced by a pointer and accumulate on the exising result. More...
 
Result ()
 Return the result. More...
 

Static Public Member Functions

template<class Iterator >
static T Accumulate (const Iterator begin, const Iterator end, const T &initialValue=T{})
 Iterate over a datastructure referenced by a pointer and return the result of its accumulation. More...
 

Private Attributes

fCorrection {}
 
fSum {}
 

#include <Math/Util.h>

Constructor & Destructor Documentation

◆ KahanSum()

template<class T>
ROOT::Math::KahanSum< T >::KahanSum ( const T &  initialValue = T{})
inline

Constructor accepting a initial value for the summation as parameter.

Definition at line 88 of file Util.h.

Member Function Documentation

◆ Accumulate()

template<class T>
template<class Iterator >
static T ROOT::Math::KahanSum< T >::Accumulate ( const Iterator  begin,
const Iterator  end,
const T &  initialValue = T{} 
)
inlinestatic

Iterate over a datastructure referenced by a pointer and return the result of its accumulation.

Can take an initial value as third parameter.

Definition at line 111 of file Util.h.

◆ Add() [1/2]

template<class T>
void ROOT::Math::KahanSum< T >::Add ( const T &  x)
inline

Single element accumulated addition.

Definition at line 91 of file Util.h.

◆ Add() [2/2]

template<class T>
template<class Iterator >
void ROOT::Math::KahanSum< T >::Add ( const Iterator  begin,
const Iterator  end 
)
inline

Iterate over a datastructure referenced by a pointer and accumulate on the exising result.

Definition at line 101 of file Util.h.

◆ Result()

template<class T>
T ROOT::Math::KahanSum< T >::Result ( )
inline

Return the result.

Definition at line 121 of file Util.h.

Member Data Documentation

◆ fCorrection

template<class T>
T ROOT::Math::KahanSum< T >::fCorrection {}
private

Definition at line 125 of file Util.h.

◆ fSum

template<class T>
T ROOT::Math::KahanSum< T >::fSum {}
private

Definition at line 124 of file Util.h.

Libraries for ROOT::Math::KahanSum< T >:
[legend]

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