
Boost : 
Subject: Re: [boost] boost.math
From: John Maddock (john_at_[hidden])
Date: 20091028 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
http://www.boost.org/doc/libs/1_40_0/libs/math/doc/sf_and_dist/html/math_toolkit/using_udt.html
* You could try computing the series using Kahan's summation algorithm
http://www.boost.org/doc/libs/1_40_0/libs/math/doc/sf_and_dist/html/math_toolkit/toolkit/internals1/series_evaluation.html
but the advantage gained is usually minimal except possibly in some special
cases.
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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk