[fpc-pascal] Re: Why this evaluates on "if" wrong ?

Milan Marusinec milan at marusinec.sk
Sun Oct 28 23:09:31 CET 2007


> This behaviour normal and while annoying, it is simply how things work 
> in the digital world, you will have to work around it.
>
> Daniël
oh yes, this is one of the possible workarounds:

function is_equal_dbl(a ,b : double ) : boolean;
const
 epsilon = 1e-14;

begin
 result:=Abs(a - b ) < epsilon;

end;

It's just one more funny thing one must realize,
when comparing real numbers with some exact
real constants. After this, I will try to never
compare doubles directly, but using tricks like
above. Because, in this digital world
1 + 0.4 - 0.4 <> 1.

Milano




More information about the fpc-pascal mailing list