OGS
MathLib::KahanSum Class Reference

Detailed Description

Definition at line 31 of file KahanSum.h.

#include <KahanSum.h>

Public Member Functions

constexpr KahanSum (double const value=0)
 
constexpr KahanSum (ranges::range auto const &range)
 
constexpr KahanSum operator+ (double const increment) const
 
constexpr KahanSum operator- (double const increment) const
 
constexpr KahanSumoperator-= (double const increment)
 
constexpr KahanSumoperator+= (double const increment)
 
constexpr double value () const
 
constexpr double operator() () const
 

Private Attributes

double value_
 
double correction_ = 0.
 

Friends

std::ostream & operator<< (std::ostream &os, KahanSum const &x)
 

Constructor & Destructor Documentation

◆ KahanSum() [1/2]

MathLib::KahanSum::KahanSum ( double const value = 0)
inlineexplicitconstexpr

Definition at line 34 of file KahanSum.h.

34: value_(value) {}
constexpr double value() const
Definition KahanSum.h:70

◆ KahanSum() [2/2]

MathLib::KahanSum::KahanSum ( ranges::range auto const & range)
inlineexplicitconstexpr

Definition at line 36 of file KahanSum.h.

36 : value_(0)
37 {
38 for (auto const v : range)
39 {
40 *this += v;
41 }
42 }
static const double v

References MathLib::v.

Member Function Documentation

◆ operator()()

double MathLib::KahanSum::operator() ( ) const
inlineconstexpr

Definition at line 71 of file KahanSum.h.

71{ return value_; }

References value_.

◆ operator+()

KahanSum MathLib::KahanSum::operator+ ( double const increment) const
inlineconstexpr

Definition at line 44 of file KahanSum.h.

45 {
46 KahanSum result = *this;
47 return result += increment;
48 }
constexpr KahanSum(double const value=0)
Definition KahanSum.h:34

◆ operator+=()

KahanSum & MathLib::KahanSum::operator+= ( double const increment)
inlineconstexpr

Definition at line 61 of file KahanSum.h.

62 {
63 double const y = increment - correction_;
64 double const t = value_ + y;
65 correction_ = (t - value_) - y;
66 value_ = t;
67 return *this;
68 }
double correction_
Definition KahanSum.h:84
static const double t

References correction_, MathLib::t, and value_.

◆ operator-()

KahanSum MathLib::KahanSum::operator- ( double const increment) const
inlineconstexpr

Definition at line 50 of file KahanSum.h.

51 {
52 KahanSum result = *this;
53 return result += -increment;
54 }

◆ operator-=()

KahanSum & MathLib::KahanSum::operator-= ( double const increment)
inlineconstexpr

Definition at line 56 of file KahanSum.h.

57 {
58 return *this += -increment;
59 }

◆ value()

double MathLib::KahanSum::value ( ) const
inlineconstexpr

Definition at line 70 of file KahanSum.h.

70{ return value_; }

References value_.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
KahanSum const & x )
friend

Definition at line 73 of file KahanSum.h.

74 {
75 auto const precision = os.precision();
76 return os << std::setprecision(
77 std::numeric_limits<double>::max_digits10)
78 << x.value() << " (± " << x.correction_ << ')'
79 << std::setprecision(precision);
80 }

Member Data Documentation

◆ correction_

double MathLib::KahanSum::correction_ = 0.
private

Definition at line 84 of file KahanSum.h.

Referenced by operator+=().

◆ value_

double MathLib::KahanSum::value_
private

Definition at line 83 of file KahanSum.h.

Referenced by operator()(), operator+=(), and value().


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