www.digitalmars.com         C & C++   DMDScript  

D - Floating point precision

reply "Martin M. Pedersen" <mmp www.moeller-pedersen.dk> writes:
Hi,

Reading "Floating Point Intermediate Values" in
http://www.digitalmars.com/d/float.html I recalled an error I have seen
before in C. In a piece of code like this:

    double d = ...some expression...;
    if ( d == ...same expression... ) {
        ...
    }

the condition was false because 'd'  had less precision than used by the
'==' operator. Testing with 'dmd', I experience the same behaviour using the
attached test program.

Such problems are hard to track down, because the code looks sensible. I
guess it is hard to avoid, but I would like to see it documented what can be
expected from a conforming D implementation, warning about such errors.


Regards,
Martin M. Pedersen
Aug 01 2002
parent "Walter" <walter digitalmars.com> writes:
You are correct.

"Martin M. Pedersen" <mmp www.moeller-pedersen.dk> wrote in message
news:aibmps$2fnm$1 digitaldaemon.com...
 Hi,

 Reading "Floating Point Intermediate Values" in
 http://www.digitalmars.com/d/float.html I recalled an error I have seen
 before in C. In a piece of code like this:

     double d = ...some expression...;
     if ( d == ...same expression... ) {
         ...
     }

 the condition was false because 'd'  had less precision than used by the
 '==' operator. Testing with 'dmd', I experience the same behaviour using

 attached test program.

 Such problems are hard to track down, because the code looks sensible. I
 guess it is hard to avoid, but I would like to see it documented what can

 expected from a conforming D implementation, warning about such errors.


 Regards,
 Martin M. Pedersen

Aug 01 2002