Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-04-24 13:43:45

| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]]On Behalf Of Jason House
| Sent: Thursday, April 24, 2003 3:57 PM
| To: boost_at_[hidden]
| Subject: [boost] Re: C++ Standard Library proposal
| -MathfunctionsforStatistics
| Well, take erf using a single parameter for precision
template <precision = 0.00001>
double erf(double x)
        // ...
  // return erfx;

For many of the proposed functions, like this one erf, IMHO this is making an
unnecessary complexity.

The implementation is probably an evaluation of a polynomial and there is little
point in not returning the full precision for the floating point type. Possible
saving from not evaluating all coefficients will be small compared to the

It probably uses some (purely imaginary) coefficients like:

static double P[] = {

static float P[] = { // note fewer terms needed for 32-bit precison?

static long double P[] = { // More coefficients for 80 or 128 bit precision?

Of course, there may be different sets of coefficients for float, double and
long double.
So three templated versions are all I believe are needed for this function.

FPType erf<FPType>(FPType)
// ... evaluate polynomial using the set of coefficient for FPType.
        return erfFPType;

float erff = erf<float>(1.234F);
double erfd = erf<double>(1.234); // erf(1.234) will chose this of course.
long double erfl = erf<long double>(1.234L);

One may want to calculate with a higher precision like double and simply return
a float( erf<double>(1.234)) which is probably accurate to the full 32-bit.

C versions: float erff(float x){ return erf<float>(x); } ...

Any rounding (for output) should take place as late as possible.

Of course, most of the inverse functions will be implemented using some
iterative Newton-style root finding, and here there IS a compromise between
accuracy and speed. Even here I am unconvinced that we need the complexity of
precision control (though Eric Ford provided a different view with a complex

For most purposes, one wants the natural precision the floating point type
provides (though sadly for some functions this is several decimal places short
of the full precision for that type - but much better than the A&S tables).


Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
Mobile mailto:pabristow_at_[hidden]

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