Hello folks,

This one looks pretty elementary, but to my big surprise
it doesn't work as I would expect.

I'd like to ask FreePascal compiler creators, how can I safely
evaluate double variables in case like this.

Sample program with comment is in attachement ...

Milano

//
// Hm. This is really weird. I assign 1 to x, which is of double type.
// Then I add 0.4 to the x, then I subtract 0.4 from x.
// So, now I should have 1 in x. But when I compare x with 1, I get
// wrong evaluation of "if x = 1 then" statement !
//
// I tried this on two different Windows Intel machines and it was wrong.
// I tried it also on Mac with PowerPC processor and it was also wrong.
// (Both Delphi & FPC compilers)
//
//                                                 [EMAIL PROTECTED]
//
program
 floating_error_1_4 ;

{$APPTYPE CONSOLE }

var
 x : double;

BEGIN
 x:=1;
 x:=x + 0.4;
 x:=x - 0.4;

 if x = 1.0 then
  writeln('OK: x = 1 ' )
 else
  writeln('Error: "if x = 1" is evaluated wrong !!!! ' );

END.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to