> I know that roundings are often tricky from language to language (Javascript 
> has not the same rules for example and a small solid state calculator has 
> different ones also).
.
.
.
> And in Perl I found these rules not very consistent.

The effect that you have discovered has nothing to do with rounding
rules.  This has to do with the internal representation of floating
point numbers given a binary numbering system.

There is no guarantee that the following will yield true:


if ( (0.0000000001 - 2 * 0.00000000005) == 0 ) {
    # this code probably won't run!
}

This isn't part of Perl or "language rounding rules".  This exact
same error would occur in C or FORTRAN or any language.

I did a quick Google search and came up with this page.  It seems
to describe this problem fairly well.

http://www.apocalypse.org/pub/u/paul/docs/cport/cport09.htm

I'm sure there are better descriptions out there that could be
found with a bit more looking.

Cheers,
Richard

Reply via email to