Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-06-20 13:09:42


On Fri, 20 Jun 2003 18:30:48 +0200 (CEST), Guillaume Melquiond
<gmelquio_at_[hidden]> wrote:

>On Fri, 20 Jun 2003, Paul A Bristow wrote:
>
>[snip]
>
>> | [*] It is not even true. Due to "double rounding" troubles,
>> | using a higher precision can lead to a value that is not the
>> | nearest number.
>>
>> Is this true even when you have a few more digits than necessary?
>> Kahan's article suggested to me that adding two guard decimal digits
>> avoids this problem. This why 40 was chosen.
>
>I don't know if we are speaking about the same thing.

I don't know either. What I know is the way floating literals should
work:

  A floating literal consists of an integer part, a decimal point,
  a fraction part, an e or E, an optionally signed integer exponent,
  and an optional type suffix. [...]
  If the scaled value is in the range of representable values for its
  type, the result is the scaled value if representable, else the
  larger or smaller representable value nearest the scaled value,
  chosen in an implementation-defined manner.

Of course "the nearest" means nearest to what you've actually written.
Also, AFAICS, there's no requirement that any representable value can
be written as a (decimal) string literal. And, theoretically, the
"chosen in an implementation-defined manner" above could simply mean
"randomly" as long as the fact is documented.

Now, I don't even get you when you say "more digits than necessary".
One thing is the number of digits you provide in the literal, one
other thing is what can effectively be stored in an object. I think
you all know that something as simple as

 float x = 1.2f;
 assert(x == 1.2);

fails on most machines.

Genny.


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