OGS
MathLib::KahanSum Class Reference

Detailed Description

Definition at line 25 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 28 of file KahanSum.h.

28: value_(value) {}
constexpr double value() const
Definition KahanSum.h:64

References value(), and value_.

Referenced by operator+(), operator+=(), operator-(), operator-=(), and operator<<.

◆ KahanSum() [2/2]

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

Definition at line 30 of file KahanSum.h.

30 : value_(0)
31 {
32 for (auto const v : range)
33 {
34 *this += v;
35 }
36 }
static const double v

References MathLib::v, and value_.

Member Function Documentation

◆ operator()()

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

Definition at line 65 of file KahanSum.h.

65{ return value_; }

References value_.

◆ operator+()

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

Definition at line 38 of file KahanSum.h.

39 {
40 KahanSum result = *this;
41 return result += increment;
42 }
constexpr KahanSum(double const value=0)
Definition KahanSum.h:28

References KahanSum().

◆ operator+=()

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

Definition at line 55 of file KahanSum.h.

56 {
57 double const y = increment - correction_;
58 double const t = value_ + y;
59 correction_ = (t - value_) - y;
60 value_ = t;
61 return *this;
62 }
double correction_
Definition KahanSum.h:78
static const double t

References KahanSum(), correction_, MathLib::t, and 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 }

References KahanSum().

◆ operator-=()

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

Definition at line 50 of file KahanSum.h.

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

References KahanSum().

◆ value()

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

Definition at line 64 of file KahanSum.h.

64{ return value_; }

References value_.

Referenced by KahanSum(), and operator<<.

◆ operator<<

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

Definition at line 67 of file KahanSum.h.

68 {
69 auto const precision = os.precision();
70 return os << std::setprecision(
71 std::numeric_limits<double>::max_digits10)
72 << x.value() << " (± " << x.correction_ << ')'
73 << std::setprecision(precision);
74 }

References KahanSum(), correction_, and value().

Member Data Documentation

◆ correction_

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

Definition at line 78 of file KahanSum.h.

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

◆ value_

double MathLib::KahanSum::value_
private

Definition at line 77 of file KahanSum.h.

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


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