Boost logo

Boost :

Subject: Re: [boost] accurate sum accumulator (kahan)
From: Gaetano Mendola (mendola_at_[hidden])
Date: 2010-07-27 13:14:47

On 07/27/2010 03:04 PM, Eric Niebler wrote:
> just tell what what text you'd like to see inserted
> where in the docs and I'll do it.

At this page:

I would add a link sum_kahan pointing to this:


Implements the summation kahan's algorithm, reducing the accumulation
error in case of floating point types.

Result Type


Depends On


Initialization Parameters

Accumulator Parameters

Extractor Parameters

Accumulator Complexity

     O(1), however compared to naive sum this accumulator
           performs 4 sum operations for each element accumulated

Extractor Complexity



#include <boost/accumulators/statistics/sum_kahan.hpp>


     accumulator_set<float, stats<tag::sum_kahan> > acc;

     BOOST_CHECK_EQUAL(0.0f, sum_kahan(acc));

     for (size_t i = 0; i < 1e6; ++i) {

     BOOST_CHECK_EQUAL(1.0f, sum_kahan(acc));

I'm not sure if this was what you meant by documentation.

Gaetano Mendola

Boost list run by bdawes at, gregod at, cpdaniel at, john at