Boost logo

Boost :

Subject: Re: [boost] boost.math
From: John Maddock (john_at_[hidden])
Date: 2009-10-28 08:56:59

> i need to implement the computation of huges series. These series are
> made of floats, and thus the error propagates.
> The problem is that the main constrain is the execution time, thus i
> must use the more "native" type possible.
> Is boost.math offer a solution to minimize this error? Which type of
> float (float, double, any structure?) must i use?

It depends why the error is creeping in:

* Computing with double is usually as fast as with float (the only exception
occurs where SSE optimizations can parrelellise the code).
* You could use either NTL::RR or MPFR to obtain high precision arithmetic -
Boost.Math contains wrappers for these that make them look "just like a
built in type" plus the glue and traits classes required to work well with
the rest of Boost.Math, but performance will be many many times slower than
a native type. See
* You could try computing the series using Kahan's summation algorithm
but the advantage gained is usually minimal except possibly in some special

Ultimately before you do any of the above, what you need to decide, is why
is the error occurring? Once you know what it is about the arithmetic
involved that generates the error then you can start to do something about
it. One trick I sometimes use if I can't spot anything obvious right away
is to write some debugging code that computes the result at two different
precisions - set it to break when the results start to drift apart, and with
luck you can then spot what's causing the problem.

HTH, John.

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