|
Boost : |
From: k.hagan_at_[hidden]
Date: 2001-05-14 05:27:05
"John Max Skaller" <skaller_at_[hidden]> wrote:
>
> 1. Use long double const. (Works for C and C++)
Please don't. If I write...
double area = pi * r * r;
...and pi is a long double then two bad things happen. Firstly,
the compiler moans that I have truncated and ought to write an
explicit cast of the result. That isn't KISS. Secondly, the
result is evaluated at long double precision (and rounded to
that precision as per IEEE) and then rounded again in the
conversion to double (area). This "double rounding" can result
in the loss of precision in the least significant digit. I
will get a more accurate value in "area" if you use doubles
throughout. (Of course, if *I* am using long double throughout,
then I want pi to be a long double.)
> 4. You do NOT need to satisfy all users.
No, but you do need to identify the user group that you are
trying to please. (In my example above, my user group is the
naive user who was taught to "use double unless you have good
reason not to".)
Paul writes that no one approach will satisfy all users and
there is no acceptable compromise. Could those who objected
to his initial submission speak up at this point and say
whether they will accept his "multi-level" proposal (subject
to everything being coded carefully and boostified)? There
really is no point in Paul submitting anything if folks are
going to turn round and say "this whole approach is wrong".
For my part...
1 I am happy with his macros, since I won't use them but
see no reason not to make his work available to C users.
2 I am happy with the "double" constants, since I believe
it fits the level of expertise within a large group of
likely users of this library.
3 I am unhappy with the extension to long double, since I
think it will encourage that same group to "go for extra
precision" and fall foul of double rounding.
4 I am unhappy with a templated constants approach, because
I'd prefer a templated inline function, which makes it
easier for the compiler to inline the constant. It also
means that no-one needs to provide the storage for the
constant, making the header self-sufficient.
So that's three user groups I'm supporting: C coders, naive
C++ users who do everything in double precision, and "Boost
regulars" who turn their noses up at anything that isn't
self-contained, zero overhead and infinitely extensible. :)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk