5#ifndef MADNESS_MISC_KAHAN_ACCUMULATOR_H_
6#define MADNESS_MISC_KAHAN_ACCUMULATOR_H_
13template <
typename T,
typename Enabler =
void>
17template <
typename Real>
19 std::enable_if_t<std::is_floating_point_v<Real>>> {
24 template <
typename Real_,
25 typename = std::enable_if_t<std::is_floating_point_v<Real_>>>
30 template <
typename Real_>
36 template <
typename Real_,
37 typename = std::enable_if_t<std::is_floating_point_v<Real_>>>
40 volatile auto t =
value_ + y;
46 template <
typename Real_,
47 typename = std::enable_if_t<std::is_floating_point_v<Real_>>>
50 volatile auto t =
value_ - minus_y;
56 template <
typename Real_>
58 *
this +=
v.correction_;
63 template <
typename Real_>
65 *
this -=
v.correction_;
77 template <
typename Archive>
87template <
typename Real1,
typename Real2>
95template <
typename Real1,
typename Real2>
103template <
typename Real1,
typename Real2>
111template <
typename Real1,
typename Real2>
119template <
typename Real1,
typename Real2>
127template <
typename Real1,
typename Real2>
135template <
typename Char,
typename Real>
136std::basic_ostream<Char>&
operator<<(std::basic_ostream<Char>& os,
137 const KahanAccumulator<Real>&
v) {
138 os <<
"{" <<
v.value() <<
"," <<
v.correction() <<
"}";
143template <
typename Complex>
145 std::enable_if_t<!std::is_floating_point_v<Complex>>> {
146 using Real =
typename Complex::value_type;
153 template <
typename Complex_,
154 typename = std::enable_if_t<!std::is_floating_point_v<Complex_>>>
157 template <
typename Complex_>
161 explicit operator Complex()
const {
return Complex(
static_cast<Real>(
real_),
static_cast<Real>(
imag_)); }
163 template <
typename Complex_,
164 typename = std::enable_if_t<!std::is_floating_point_v<Complex_>>>
171 template <
typename Complex_,
172 typename = std::enable_if_t<!std::is_floating_point_v<Complex_>>>
179 template <
typename Complex_>
186 template <
typename Complex_>
193 template <
typename Archive>
static const double v
Definition hatom_sf_dirac.cc:20
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
std::ostream & operator<<(std::ostream &os, const particle< PDIM > &p)
Definition lowrankfunction.h:452
std::vector< CCPairFunction< T, NDIM > > operator+(const CCPairFunction< T, NDIM > c1, const CCPairFunction< T, NDIM > &c2)
Definition ccpairfunction.h:1066
std::vector< CCPairFunction< T, NDIM > > operator-(const std::vector< CCPairFunction< T, NDIM > > c1, const std::vector< CCPairFunction< T, NDIM > > &c2)
Definition ccpairfunction.h:1082
double imag(double x)
Definition complexfun.h:56
double real(double x)
Definition complexfun.h:52
static const double c
Definition relops.cc:10
RealAccumulator imag_
Definition kahan_accumulator.h:200
KahanAccumulator(const Complex_ &v)
Definition kahan_accumulator.h:155
KahanAccumulator & operator-=(const KahanAccumulator< Complex_ > &v)
Definition kahan_accumulator.h:187
KahanAccumulator(const KahanAccumulator< Complex_ > &v)
Definition kahan_accumulator.h:158
KahanAccumulator(const KahanAccumulator &)=default
KahanAccumulator< Real > RealAccumulator
Definition kahan_accumulator.h:147
KahanAccumulator & operator+=(const Complex_ &v)
Definition kahan_accumulator.h:165
KahanAccumulator & operator-=(const Complex_ &v)
Definition kahan_accumulator.h:173
KahanAccumulator & operator+=(const KahanAccumulator< Complex_ > &v)
Definition kahan_accumulator.h:180
KahanAccumulator & operator=(const KahanAccumulator &)=default
typename Complex::value_type Real
Definition kahan_accumulator.h:146
RealAccumulator real_
Definition kahan_accumulator.h:199
void serialize(Archive &ar)
Definition kahan_accumulator.h:194
KahanAccumulator()=default
KahanAccumulator & operator-=(Real_ v)
Definition kahan_accumulator.h:48
KahanAccumulator()=default
KahanAccumulator & operator+=(Real_ v)
Definition kahan_accumulator.h:38
KahanAccumulator & operator+=(const KahanAccumulator< Real_ > &v)
Definition kahan_accumulator.h:57
void serialize(Archive &ar)
Definition kahan_accumulator.h:78
Real value_
Definition kahan_accumulator.h:83
KahanAccumulator(Real v, Real c)
Definition kahan_accumulator.h:28
KahanAccumulator & operator-=(const KahanAccumulator< Real_ > &v)
Definition kahan_accumulator.h:64
auto correction() const
Definition kahan_accumulator.h:75
KahanAccumulator(Real_ v)
Definition kahan_accumulator.h:26
auto value() const
Definition kahan_accumulator.h:74
KahanAccumulator operator-() const
Definition kahan_accumulator.h:70
KahanAccumulator & operator=(const KahanAccumulator &)=default
KahanAccumulator(KahanAccumulator< Real_ > v)
Definition kahan_accumulator.h:31
Real correction_
Definition kahan_accumulator.h:84
KahanAccumulator(const KahanAccumulator &)=default
Definition kahan_accumulator.h:14