Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Class template sum

boost::histogram::accumulators::sum — Uses Neumaier algorithm to compute accurate sums.

Synopsis

// In header: <boost/histogram/accumulators/sum.hpp>

template<typename RealType> 
class sum {
public:
  // construct/copy/destruct
  sum() = default;
  explicit sum(const RealType &) noexcept;
  sum & operator=(const RealType &) noexcept;

  // public member functions
  sum & operator++();
  sum & operator+=(const RealType &);
  sum & operator *=(const RealType &);
  template<typename T> bool operator==(const sum< T > &) const noexcept;
  template<typename T> bool operator!=(const T &) const noexcept;
  const RealType & large() const;
  const RealType & small() const;
  operator RealType() const;
  template<typename Archive> void serialize(Archive &, unsigned);
};

Description

The algorithm uses memory for two floats and is three to five times slower compared to a simple floating point number used to accumulate a sum, but the relative error of the sum is at the level of the machine precision, independent of the number of samples.

A. Neumaier, Zeitschrift fuer Angewandte Mathematik und Mechanik 54 (1974) 39-51.

sum public construct/copy/destruct

  1. sum() = default;
  2. explicit sum(const RealType & value) noexcept;
    Initialize sum to value.
  3. sum & operator=(const RealType & value) noexcept;
    Set sum to value.

sum public member functions

  1. sum & operator++();
    Increment sum by one.
  2. sum & operator+=(const RealType & value);
    Increment sum by value.
  3. sum & operator *=(const RealType & value);
    Scale by value.
  4. template<typename T> bool operator==(const sum< T > & rhs) const noexcept;
  5. template<typename T> bool operator!=(const T & rhs) const noexcept;
  6. const RealType & large() const;
    Return large part of the sum.
  7. const RealType & small() const;
    Return small part of the sum.
  8. operator RealType() const;
  9. template<typename Archive> void serialize(Archive & ar, unsigned);

PrevUpHomeNext