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_>
 
   32      : value_(
v.value_), correction_(
v.correction_) {}
 
 
   34  explicit operator Real()
 const { 
return value_ + correction_; }
 
   36  template <
typename Real_,
 
   37            typename = std::enable_if_t<std::is_floating_point_v<Real_>>>
 
   39    volatile auto y = 
v - correction_;
 
   40    volatile auto t = value_ + y;
 
   41    correction_ = (t - value_) - y;
 
 
   46  template <
typename Real_,
 
   47            typename = std::enable_if_t<std::is_floating_point_v<Real_>>>
 
   49    volatile auto minus_y = 
v + correction_;
 
   50    volatile auto t = value_ - minus_y;
 
   51    correction_ = (t - value_) + minus_y;
 
 
   56  template <
typename Real_>
 
   58    *
this += 
v.correction_;
 
 
   63  template <
typename Real_>
 
   65    *
this -= 
v.correction_;
 
 
   74  auto value()
 const { 
return value_; }
 
   77  template <
typename Archive>
 
   79    ar& value_& correction_;
 
 
   83  Real value_ = Real{0};
 
   84  Real correction_ = Real{0};
 
 
   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_>
 
  159      : real_(
v.real_), imag_(
v.imag_) {}
 
 
  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 DFParameters.h:10
std::ostream & operator<<(std::ostream &os, const particle< PDIM > &p)
Definition lowrankfunction.h:401
std::vector< CCPairFunction< T, NDIM > > operator-(const std::vector< CCPairFunction< T, NDIM > > c1, const std::vector< CCPairFunction< T, NDIM > > &c2)
Definition ccpairfunction.h:1060
double imag(double x)
Definition complexfun.h:56
std::vector< CCPairFunction< T, NDIM > > operator+(const std::vector< CCPairFunction< T, NDIM > > c1, const std::vector< CCPairFunction< T, NDIM > > &c2)
Definition ccpairfunction.h:1052
double real(double x)
Definition complexfun.h:52
static const double c
Definition relops.cc:10
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 & 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
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
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
KahanAccumulator(const KahanAccumulator &)=default
Definition kahan_accumulator.h:14