[fpc-pascal] floating point an FPC

Flávio Etrusco flavio.etrusco at gmail.com
Tue Mar 2 14:20:17 CET 2010


On Mon, Mar 1, 2010 at 6:32 PM, ik <idokan at gmail.com> wrote:
>
> http://ik.homelinux.org/
>
>
> On Mon, Mar 1, 2010 at 23:20, Jerry <lanceboyle at 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



More information about the fpc-pascal mailing list