Boost logo

Boost Users :

Subject: Re: [Boost-users] [accumulators] Is there a reset function yet?
From: Tim Odenthal (Tim.Odenthal_at_[hidden])
Date: 2010-05-25 06:08:57


On Friday 21 May 2010 21:23:53 boost-users-request_at_[hidden] wrote:
> > By the way, does the accumulator do something to prevent an overflow when
> > I add up everything into one variable?
>
> No. It uses native intrinsics for raw performance. If you want anything
> fancy, you can use your own UDT for samples that check for overflow.
> Some construction required. :-( If you do build such a thing, I would
> consider making it an official part of Accumulators.

Well I'm absolutely no specialist in this, but for my averaging problem it
would be enough to compare the "sum" and each new element to
0.5*std::numeric_limits<T>::max()-std::numeric_limits<T>::epsilon() and save
the current value "somewhere" (a std::vector?) when this limit is reached.
Then, at extraction, one would have to calculate the weighted sum of the
entries of that vector.
Do you think that's a good approach?

>
> > And does it prevent a loss of precision,
> > when at a late stage the variable I sum everything into is very big, but
> > the thing I add is very small?
>
> No. See above.

Here (not being an expert in numerics) I have no clue how to tackle this. A
certain loss of precision has to be accepted, probably, but how much is still
acceptable?

>
> > Maybe it would be a good idea to mention this in the documentation, as
> > well...
>
> Indeed. Could you file a ticket at http://svn.boost.org so this doesn't
> get lost?
Yes, did that. (Ticket #4255)
>
> Thanks,
>
> --
> Eric Niebler

Thanks,

Tim

-- 
Dipl.-Phys. Tim Odenthal
Division of Mechatronics, Biostatistics and Sensors (MeBioS)
Email:  Tim.Odenthal_at_[hidden]
Full details at http://www.kuleuven.be/cv/u0064388e.htm

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net