Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-06-25 03:33:19


I am now confident that I understand what you are proposing.

It certainly seems "The Right Thing To Do" (tm)
but is more complicated for me to calculate, though not too bad.

I would welcome confirmation from other potential users that they agree.

Paul

PS Of course the problem of macro, function, template function is still to be
resolved and is still being worked on elsewhere.

PPS I couldn't see in the ISO C++ spec if float and double is required to be 32
and 64 bits. Any Language Lawyers care to say?

| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]]On Behalf Of Guillaume Melquiond
| Sent: Wednesday, June 25, 2003 8:59 AM
| To: Boost mailing list
| Subject: RE: [boost] Re: Math constants - nearest values
|
|
| On Sun, 22 Jun 2003, Paul A Bristow wrote:
|
| > | Consequently, more than one constant out of 10000 may suffer
| > | from this problem. So it is rare, but it is not impossible.
| > | It's why I was suggesting that a library should provide a
| > | mean to know if a number representing a constant is the
| > | nearest or not.
| >
| > One constant out of 10000 seems a rather small risk.
|
| > Can't we just check that all the constants we offer are in fact the
| > nearest?
|
| Yes.
|
| > Since very few contain many zeros, I think I am prepared to wager a few
| > beers on this one!
|
| > So does this mean that the presentation function will use the 'exactly
| > representable' decimal digits appropriate for the floating point format
| > (choice of 5) and for the FP type float, double, long double to give to
| > the compiler to use?
|
| Sorry, I'm not sure I clearly understand what you mean. What I would do is
| something like
|
| float the_constant_f = ... /* a 24 binary digits representation */;
| double the_constant_d = ... /* a 53 binary digits representation */;
| long double the_constant_ld =
| #ifdef LONG_DOUBLE_IS_80_BITS
| ... /* a 64 binary digits representation */;
| #elif defined(LONG_DOUBLE_IS_128_BITS)
| ... /* a 102 binary digits representation */;
| #else /* we don't know this floating-point format */
| ... /* a 40 decimal digits approximation */;
| #define the_constant_LONG_DOUBLE_MAY_NOT_BE_ACCURATE
| #endif
| /* And then there would be all the wrappers... */
|
| The binary representations will be exact values in order to avoid compiler
| rounding. So all possible floating-point formats should be thought of.
| However, if one of them is missing, we fall back on a common 40 decimal
| digits constant. Since we can't be sure there won't be any rounding
| problem, we flag the result as being "maybe inaccurate". Does it make
| sense?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk