## D - Floating point precision

"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

begin 666 test.d
M:6UP;W)T(&UA=& [#0H-"F-H87(J(&)O;VPR<W1R*&)I="!B*0T*>PT*("
M(&EF("AB*2![#0H ("  ("  (')E='5R;B B=')U92([#0H ("  ?2!E;'-E
M('L-"B  ("  ("  <F5T=7)N(")F86QS92([#0H ("  ?0T*?0T*#0H-"FEN
M="!M86EN*&-H87);75M=(&%R9W,I#0I[#0H ("  9FQO870 ("  ("  9CL-
M"B  ("!D;W5B;&4 ("  ("!D.PT*("  (&5X=&5N9&5D("  (&4[#0H-"B
M("!F(#T 97AP*#\$I.PT*("  (&0 /2!E>' H,2D[#0H ("  92 ](&5X<" Q
M*3L-" T*("  ('!R:6YT9B B9FQO870Z("5S7&XB+"!B;V]L,G-T<BAF/3UE
M>' H,2DI*3L-"B  ("!P<FEN=&8H(F1O=6)L93H )7-<;B(L(&)O;VPR<W1R
M*&0]/65X<" Q*2DI.PT*("  ('!R:6YT9B B97AT96YD960Z("5S7&XB+"!B
M;V]L,G-T<BAE/3UE>' H,2DI*3L-" T*("  ('!R:6YT9B B9B ]("5'7&XB
;+"!F*3L-" T*("  (')E='5R;B P.PT*?0T*
`
end
```
Aug 01 2002
"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

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