
Boost : 
From: James Dennett (jdennett_at_[hidden])
Date: 20010515 07:08:42
Corwin Joy wrote:
>
>  In boost_at_y..., "Paul A. Bristow" <pbristow_at_h...> wrote:
> > There has been a lot of dissention about the format of my proposed
> > mathematical constants.
> > <..snip..> e.g.
> > a collection of
> > namespace math_double_constants
> > {
> > const double pi = 31459;
> > }
>
> Not to rain on your parade, but as a mathematician I can tell you
> that what you are doing here is a *bad* idea anyway.
As a methematician and a programmer, I can tell you that it's
not :)
> If you want to
> do serious numerical work, then I would *strongly* recommend not
> defining PI as a fixed sequence of digits like you do above because
> then you will never be able to take advantage of the full numerical
> accuracy of the machine you are working on.
Unless you give enough digits, in which case you may well be
able to.
> (Plus, it is less
> portable.)
If compiler problems turning digit strings into numbers are
taken into account, that may be true.
> Better, is to use constants that are calculated to the
> precision of the machine you are working on e.g.
> const double pi = 4.0 *(atan(0.5) + atan(0.2) + atan(0.125));
It is unlikely that your definition of pi will give the best
accuracy because of errors during the calculation. A constant
should have an error in (at most) the last binary digit, if
the compiler isn't completely useless.
> If you do something like above
> double pi = 3.15; // (rounded to 2 dp)
>
> the numerical analysts will likely be displeased.
But if you put enough digits there, they'll be happy.
 James Dennett
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk