LibreOffice Module sc (master)  1
Public Member Functions | Private Attributes | List of all members
KahanSum Class Reference

This class provides LO with Kahan summation algorithm About this algorithm: https://en.wikipedia.org/wiki/Kahan_summation_algorithm For general purpose software we assume first order error is enough. More...

#include <kahan.hxx>

Public Member Functions

constexpr KahanSum ()=default
 
constexpr KahanSum (double x_0)
 
constexpr KahanSum (double x_0, double err_0)
 
constexpr KahanSum (const sc::op::KahanSumSimple &sum)
 
constexpr KahanSum (const KahanSum &fSum)=default
 
void add (double x_i)
 Adds a value to the sum using Kahan summation. More...
 
void add (const KahanSum &fSum)
 Adds a value to the sum using Kahan summation. More...
 
void subtract (const KahanSum &fSum)
 Substracts a value to the sum using Kahan summation. More...
 
constexpr KahanSum operator- () const
 
constexpr KahanSumoperator= (double fSum)
 
constexpr KahanSumoperator= (const KahanSum &fSum)=default
 
void operator+= (const KahanSum &fSum)
 
void operator+= (double fSum)
 
void operator-= (const KahanSum &fSum)
 
void operator-= (double fSum)
 
KahanSum operator+ (double fSum) const
 
KahanSum operator+ (const KahanSum &fSum) const
 
KahanSum operator- (double fSum) const
 
KahanSum operator- (const KahanSum &fSum) const
 
constexpr void operator*= (double fTimes)
 In some parts of the code of interpr_.cxx this may be used for product instead of sum. More...
 
constexpr void operator/= (double fDivides)
 
KahanSum operator* (const KahanSum &fTimes) const
 
constexpr KahanSum operator* (double fTimes) const
 
KahanSum operator/ (const KahanSum &fDivides) const
 
constexpr KahanSum operator/ (double fTimes) const
 
constexpr bool operator< (const KahanSum &fSum) const
 
constexpr bool operator< (double fSum) const
 
constexpr bool operator> (const KahanSum &fSum) const
 
constexpr bool operator> (double fSum) const
 
constexpr bool operator<= (const KahanSum &fSum) const
 
constexpr bool operator<= (double fSum) const
 
constexpr bool operator>= (const KahanSum &fSum) const
 
constexpr bool operator>= (double fSum) const
 
constexpr bool operator== (const KahanSum &fSum) const
 
constexpr bool operator!= (const KahanSum &fSum) const
 
constexpr double * getSum ()
 
constexpr double * getError ()
 
constexpr double get () const
 Returns the final sum. More...
 

Private Attributes

double m_fSum = 0
 
double m_fError = 0
 

Detailed Description

This class provides LO with Kahan summation algorithm About this algorithm: https://en.wikipedia.org/wiki/Kahan_summation_algorithm For general purpose software we assume first order error is enough.

This class could be made constexpr if needed.

Definition at line 23 of file kahan.hxx.

Constructor & Destructor Documentation

constexpr KahanSum::KahanSum ( )
default
constexpr KahanSum::KahanSum ( double  x_0)
inline

Definition at line 28 of file kahan.hxx.

constexpr KahanSum::KahanSum ( double  x_0,
double  err_0 
)
inline

Definition at line 33 of file kahan.hxx.

constexpr KahanSum::KahanSum ( const sc::op::KahanSumSimple sum)
inline

Definition at line 39 of file kahan.hxx.

constexpr KahanSum::KahanSum ( const KahanSum fSum)
default

Member Function Documentation

void KahanSum::add ( double  x_i)
inline

Adds a value to the sum using Kahan summation.

Parameters
x_i

Definition at line 52 of file kahan.hxx.

References m_fError, m_fSum, and t.

Referenced by add(), operator+(), operator+=(), operator-(), operator-=(), and subtract().

void KahanSum::add ( const KahanSum fSum)
inline

Adds a value to the sum using Kahan summation.

Parameters
fSum

Definition at line 66 of file kahan.hxx.

References add(), m_fError, and m_fSum.

constexpr double KahanSum::get ( ) const
inline
constexpr double* KahanSum::getError ( )
inline

Definition at line 200 of file kahan.hxx.

References m_fError.

constexpr double* KahanSum::getSum ( )
inline

Definition at line 199 of file kahan.hxx.

References m_fSum.

constexpr bool KahanSum::operator!= ( const KahanSum fSum) const
inline

Definition at line 194 of file kahan.hxx.

References m_fError, and m_fSum.

KahanSum KahanSum::operator* ( const KahanSum fTimes) const
inline

Definition at line 152 of file kahan.hxx.

References m_fError, and m_fSum.

constexpr KahanSum KahanSum::operator* ( double  fTimes) const
inline

Definition at line 157 of file kahan.hxx.

References sc::fTimes.

constexpr void KahanSum::operator*= ( double  fTimes)
inline

In some parts of the code of interpr_.cxx this may be used for product instead of sum.

This operator shall be used for that task.

Definition at line 140 of file kahan.hxx.

References sc::fTimes, m_fError, and m_fSum.

KahanSum KahanSum::operator+ ( double  fSum) const
inline

Definition at line 108 of file kahan.hxx.

References add().

KahanSum KahanSum::operator+ ( const KahanSum fSum) const
inline

Definition at line 115 of file kahan.hxx.

void KahanSum::operator+= ( const KahanSum fSum)
inline

Definition at line 100 of file kahan.hxx.

References add().

void KahanSum::operator+= ( double  fSum)
inline

Definition at line 102 of file kahan.hxx.

References add().

constexpr KahanSum KahanSum::operator- ( ) const
inline

Definition at line 83 of file kahan.hxx.

References m_fError, and m_fSum.

KahanSum KahanSum::operator- ( double  fSum) const
inline

Definition at line 122 of file kahan.hxx.

References add().

KahanSum KahanSum::operator- ( const KahanSum fSum) const
inline

Definition at line 129 of file kahan.hxx.

void KahanSum::operator-= ( const KahanSum fSum)
inline

Definition at line 104 of file kahan.hxx.

References subtract().

void KahanSum::operator-= ( double  fSum)
inline

Definition at line 106 of file kahan.hxx.

References add().

KahanSum KahanSum::operator/ ( const KahanSum fDivides) const
inline

Definition at line 164 of file kahan.hxx.

References get().

constexpr KahanSum KahanSum::operator/ ( double  fTimes) const
inline

Definition at line 166 of file kahan.hxx.

References sc::fTimes.

constexpr void KahanSum::operator/= ( double  fDivides)
inline

Definition at line 146 of file kahan.hxx.

References m_fError, and m_fSum.

constexpr bool KahanSum::operator< ( const KahanSum fSum) const
inline

Definition at line 173 of file kahan.hxx.

References get().

constexpr bool KahanSum::operator< ( double  fSum) const
inline

Definition at line 175 of file kahan.hxx.

constexpr bool KahanSum::operator<= ( const KahanSum fSum) const
inline

Definition at line 181 of file kahan.hxx.

References get().

constexpr bool KahanSum::operator<= ( double  fSum) const
inline

Definition at line 183 of file kahan.hxx.

constexpr KahanSum& KahanSum::operator= ( double  fSum)
inline

Definition at line 91 of file kahan.hxx.

References m_fError, and m_fSum.

constexpr KahanSum& KahanSum::operator= ( const KahanSum fSum)
default
constexpr bool KahanSum::operator== ( const KahanSum fSum) const
inline

Definition at line 189 of file kahan.hxx.

References m_fError, and m_fSum.

constexpr bool KahanSum::operator> ( const KahanSum fSum) const
inline

Definition at line 177 of file kahan.hxx.

References get().

constexpr bool KahanSum::operator> ( double  fSum) const
inline

Definition at line 179 of file kahan.hxx.

constexpr bool KahanSum::operator>= ( const KahanSum fSum) const
inline

Definition at line 185 of file kahan.hxx.

References get().

constexpr bool KahanSum::operator>= ( double  fSum) const
inline

Definition at line 187 of file kahan.hxx.

void KahanSum::subtract ( const KahanSum fSum)
inline

Substracts a value to the sum using Kahan summation.

Parameters
fSum

Definition at line 76 of file kahan.hxx.

References add(), m_fError, and m_fSum.

Referenced by operator-=().

Member Data Documentation

double KahanSum::m_fError = 0
private
double KahanSum::m_fSum = 0
private

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