On Mon, Mar 1, 2010 at 6:32 PM, ik <ido...@gmail.com> wrote:
>
> http://ik.homelinux.org/
>
>
> On Mon, Mar 1, 2010 at 23:20, Jerry <lancebo...@qwest.net> wrote:
>>
>> Don't compare floating points. Ever. Now you see why.
>
> So if I need for example to compare currency or something that is floating
> point, how do I do that ?
>

Let me my 2cent obvious comments too:

1) Just in case you don't know, Curreny is ok in the sense that it's
exact - ok, FP is exact in it's own way ;) -, but keep in mind that
its precision is just 4 decimal places, so you must be aware of
precision loss too.

2) You can determine what is "close enough" for your comparison and
use Abs(A - B) < MarginOfError (and of course variants of that code).
I vaguely remember some performance problem with Abs (in Delphi or in
general? does FP have a signal bit?), so let someone expert chime in
to say whether you should Abs or two comparisons intead ;-)

Best regards,
Flávio
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to