1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Class template sum</title> 5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Histogram"> 8<link rel="up" href="../../../histogram/reference.html#header.boost.histogram.accumulators.sum_hpp" title="Header <boost/histogram/accumulators/sum.hpp>"> 9<link rel="prev" href="mean.html" title="Class template mean"> 10<link rel="next" href="thread_safe.html" title="Class template thread_safe"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="mean.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../histogram/reference.html#header.boost.histogram.accumulators.sum_hpp"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="thread_safe.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="refentry"> 26<a name="boost.histogram.accumulators.sum"></a><div class="titlepage"></div> 27<div class="refnamediv"> 28<h2><span class="refentrytitle">Class template sum</span></h2> 29<p>boost::histogram::accumulators::sum — Uses Neumaier algorithm to compute accurate sums of floats. </p> 30</div> 31<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2> 32<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: <<a class="link" href="../../../histogram/reference.html#header.boost.histogram.accumulators.sum_hpp" title="Header <boost/histogram/accumulators/sum.hpp>">boost/histogram/accumulators/sum.hpp</a>> 33 34</span><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> ValueType<span class="special">></span> 35<span class="keyword">class</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">{</span> 36<span class="keyword">public</span><span class="special">:</span> 37 <span class="comment">// types</span> 38 <span class="keyword">typedef</span> <span class="identifier">ValueType</span> <a name="boost.histogram.accumulators.sum.value_type"></a><span class="identifier">value_type</span><span class="special">;</span> 39 <span class="keyword">typedef</span> <span class="keyword">const</span> <span class="identifier">value_type</span> <span class="special">&</span> <a name="boost.histogram.accumulators.sum.const_reference"></a><span class="identifier">const_reference</span><span class="special">;</span> 40 41 <span class="comment">// <a class="link" href="sum.html#boost.histogram.accumulators.sumconstruct-copy-destruct">construct/copy/destruct</a></span> 42 <a class="link" href="sum.html#idm45503931274944-bb"><span class="identifier">sum</span></a><span class="special">(</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">default</span><span class="special">;</span> 43 <a class="link" href="sum.html#idm45503931274544-bb"><span class="identifier">sum</span></a><span class="special">(</span><span class="identifier">const_reference</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> 44 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> T<span class="special">></span> <a class="link" href="sum.html#idm45503931273136-bb"><span class="identifier">sum</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a><span class="special"><</span> <span class="identifier">T</span> <span class="special">></span> <span class="special">&</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> 45 <a class="link" href="sum.html#idm45503931270608-bb"><span class="identifier">sum</span></a><span class="special">(</span><span class="identifier">const_reference</span><span class="special">,</span> <span class="identifier">const_reference</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> 46 47 <span class="comment">// <a class="link" href="sum.html#idm45503931313744-bb">public member functions</a></span> 48 <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a class="link" href="sum.html#idm45503931313184-bb"><span class="keyword">operator</span><span class="special">++</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> 49 <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a class="link" href="sum.html#idm45503931311648-bb"><span class="keyword">operator</span><span class="special">+=</span></a><span class="special">(</span><span class="identifier">const_reference</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> 50 <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a class="link" href="sum.html#idm45503931309408-bb"><span class="keyword">operator</span><span class="special">+=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> 51 <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a class="link" href="sum.html#idm45503931306736-bb"><span class="keyword">operator</span> <span class="special">*=</span></a><span class="special">(</span><span class="identifier">const_reference</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> 52 <span class="keyword">bool</span> <a class="link" href="sum.html#idm45503931304512-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 53 <span class="keyword">bool</span> <a class="link" href="sum.html#idm45503931302416-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 54 <span class="identifier">value_type</span> <a class="link" href="sum.html#idm45503931300320-bb"><span class="identifier">value</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 55 <span class="identifier">const_reference</span> <a class="link" href="sum.html#idm45503931299056-bb"><span class="identifier">large</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 56 <span class="identifier">const_reference</span> <a class="link" href="sum.html#idm45503931297792-bb"><span class="identifier">small</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 57 <span class="keyword">explicit</span> <a class="link" href="sum.html#idm45503931296528-bb"><span class="keyword">operator</span> <span class="identifier">value_type</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 58 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> Archive<span class="special">></span> <span class="keyword">void</span> <a class="link" href="sum.html#idm45503931295296-bb"><span class="identifier">serialize</span></a><span class="special">(</span><span class="identifier">Archive</span> <span class="special">&</span><span class="special">,</span> <span class="keyword">unsigned</span><span class="special">)</span><span class="special">;</span> 59 <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a class="link" href="sum.html#idm45503931292544-bb"><span class="keyword">operator</span> <span class="special">*=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> 60 <a class="link" href="sum.html" title="Class template sum">sum</a> <a class="link" href="sum.html#idm45503931290160-bb"><span class="keyword">operator</span> <span class="special">*</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 61 <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a class="link" href="sum.html#idm45503931287936-bb"><span class="keyword">operator</span><span class="special">/=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> 62 <a class="link" href="sum.html" title="Class template sum">sum</a> <a class="link" href="sum.html#idm45503931285552-bb"><span class="keyword">operator</span><span class="special">/</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 63 <span class="keyword">bool</span> <a class="link" href="sum.html#idm45503931283328-bb"><span class="keyword">operator</span><span class="special"><</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 64 <span class="keyword">bool</span> <a class="link" href="sum.html#idm45503931281232-bb"><span class="keyword">operator</span><span class="special">></span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 65 <span class="keyword">bool</span> <a class="link" href="sum.html#idm45503931279136-bb"><span class="keyword">operator</span><span class="special"><=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 66 <span class="keyword">bool</span> <a class="link" href="sum.html#idm45503931277040-bb"><span class="keyword">operator</span><span class="special">>=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span> 67<span class="special">}</span><span class="special">;</span></pre></div> 68<div class="refsect1"> 69<a name="idm45113196309232"></a><h2>Description</h2> 70<p>The algorithm is an improved Kahan algorithm (<a href="https://en.wikipedia.org/wiki/Kahan_summation_algorithm" target="_top">https://en.wikipedia.org/wiki/Kahan_summation_algorithm</a>). The algorithm uses memory for two numbers and is three to five times slower compared to using a single number 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.</p> 71<p>A. Neumaier, Zeitschrift fuer Angewandte Mathematik und Mechanik 54 (1974) 39-51. </p> 72<div class="refsect2"> 73<a name="idm45113196307136"></a><h3> 74<a name="boost.histogram.accumulators.sumconstruct-copy-destruct"></a><code class="computeroutput">sum</code> 75 public 76 construct/copy/destruct</h3> 77<div class="orderedlist"><ol class="orderedlist" type="1"> 78<li class="listitem"><pre class="literallayout"><a name="idm45503931274944-bb"></a><span class="identifier">sum</span><span class="special">(</span><span class="special">)</span> <span class="special">=</span> <span class="keyword">default</span><span class="special">;</span></pre></li> 79<li class="listitem"> 80<pre class="literallayout"><a name="idm45503931274544-bb"></a><span class="identifier">sum</span><span class="special">(</span><span class="identifier">const_reference</span> value<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>Initialize sum to value and allow implicit conversion. </li> 81<li class="listitem"> 82<pre class="literallayout"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> T<span class="special">></span> <a name="idm45503931273136-bb"></a><span class="identifier">sum</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a><span class="special"><</span> <span class="identifier">T</span> <span class="special">></span> <span class="special">&</span> s<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>Allow implicit conversion from sum<T> </li> 83<li class="listitem"> 84<pre class="literallayout"><a name="idm45503931270608-bb"></a><span class="identifier">sum</span><span class="special">(</span><span class="identifier">const_reference</span> large<span class="special">,</span> <span class="identifier">const_reference</span> small<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>Initialize sum explicitly with large and small parts. </li> 85</ol></div> 86</div> 87<div class="refsect2"> 88<a name="idm45113196277072"></a><h3> 89<a name="idm45503931313744-bb"></a><code class="computeroutput">sum</code> public member functions</h3> 90<div class="orderedlist"><ol class="orderedlist" type="1"> 91<li class="listitem"> 92<pre class="literallayout"><a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a name="idm45503931313184-bb"></a><span class="keyword">operator</span><span class="special">++</span><span class="special">(</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>Increment sum by one. </li> 93<li class="listitem"> 94<pre class="literallayout"><a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a name="idm45503931311648-bb"></a><span class="keyword">operator</span><span class="special">+=</span><span class="special">(</span><span class="identifier">const_reference</span> value<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>Increment sum by value. </li> 95<li class="listitem"> 96<pre class="literallayout"><a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a name="idm45503931309408-bb"></a><span class="keyword">operator</span><span class="special">+=</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> s<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>Add another sum. </li> 97<li class="listitem"> 98<pre class="literallayout"><a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a name="idm45503931306736-bb"></a><span class="keyword">operator</span> <span class="special">*=</span><span class="special">(</span><span class="identifier">const_reference</span> value<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>Scale by value. </li> 99<li class="listitem"><pre class="literallayout"><span class="keyword">bool</span> <a name="idm45503931304512-bb"></a><span class="keyword">operator</span><span class="special">==</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> rhs<span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li> 100<li class="listitem"><pre class="literallayout"><span class="keyword">bool</span> <a name="idm45503931302416-bb"></a><span class="keyword">operator</span><span class="special">!=</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> rhs<span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li> 101<li class="listitem"> 102<pre class="literallayout"><span class="identifier">value_type</span> <a name="idm45503931300320-bb"></a><span class="identifier">value</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>Return value of the sum. </li> 103<li class="listitem"> 104<pre class="literallayout"><span class="identifier">const_reference</span> <a name="idm45503931299056-bb"></a><span class="identifier">large</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>Return large part of the sum. </li> 105<li class="listitem"> 106<pre class="literallayout"><span class="identifier">const_reference</span> <a name="idm45503931297792-bb"></a><span class="identifier">small</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre>Return small part of the sum. </li> 107<li class="listitem"><pre class="literallayout"><span class="keyword">explicit</span> <a name="idm45503931296528-bb"></a><span class="keyword">operator</span> <span class="identifier">value_type</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li> 108<li class="listitem"><pre class="literallayout"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> Archive<span class="special">></span> <span class="keyword">void</span> <a name="idm45503931295296-bb"></a><span class="identifier">serialize</span><span class="special">(</span><span class="identifier">Archive</span> <span class="special">&</span> ar<span class="special">,</span> <span class="keyword">unsigned</span><span class="special">)</span><span class="special">;</span></pre></li> 109<li class="listitem"><pre class="literallayout"><a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a name="idm45503931292544-bb"></a><span class="keyword">operator</span> <span class="special">*=</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> rhs<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li> 110<li class="listitem"><pre class="literallayout"><a class="link" href="sum.html" title="Class template sum">sum</a> <a name="idm45503931290160-bb"></a><span class="keyword">operator</span> <span class="special">*</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> rhs<span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li> 111<li class="listitem"><pre class="literallayout"><a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> <a name="idm45503931287936-bb"></a><span class="keyword">operator</span><span class="special">/=</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> rhs<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li> 112<li class="listitem"><pre class="literallayout"><a class="link" href="sum.html" title="Class template sum">sum</a> <a name="idm45503931285552-bb"></a><span class="keyword">operator</span><span class="special">/</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> rhs<span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li> 113<li class="listitem"><pre class="literallayout"><span class="keyword">bool</span> <a name="idm45503931283328-bb"></a><span class="keyword">operator</span><span class="special"><</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> rhs<span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li> 114<li class="listitem"><pre class="literallayout"><span class="keyword">bool</span> <a name="idm45503931281232-bb"></a><span class="keyword">operator</span><span class="special">></span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> rhs<span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li> 115<li class="listitem"><pre class="literallayout"><span class="keyword">bool</span> <a name="idm45503931279136-bb"></a><span class="keyword">operator</span><span class="special"><=</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> rhs<span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li> 116<li class="listitem"><pre class="literallayout"><span class="keyword">bool</span> <a name="idm45503931277040-bb"></a><span class="keyword">operator</span><span class="special">>=</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="sum.html" title="Class template sum">sum</a> <span class="special">&</span> rhs<span class="special">)</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></pre></li> 117</ol></div> 118</div> 119</div> 120</div> 121<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 122<td align="left"></td> 123<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Hans 124 Dembinski<p> 125 Distributed under the Boost Software License, Version 1.0. (See accompanying 126 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 127 </p> 128</div></td> 129</tr></table> 130<hr> 131<div class="spirit-nav"> 132<a accesskey="p" href="mean.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../histogram/reference.html#header.boost.histogram.accumulators.sum_hpp"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="thread_safe.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 133</div> 134</body> 135</html> 136