[Israel.pm] perl arithmetic

Yuval Kogman lists at woobling.org
Sun Apr 18 06:51:34 PDT 2004


On Sun, Apr 18, 2004 at 16:30:16 +0300, Pinkhas Nisanov wrote:
> ==> perl -e 'print 18.99+4.56==23.55 ? "TRUE" : "FALSE", "\n"'
> FALSE
> ==> perl -e 'print 18.98+4.57==23.55 ? "TRUE" : "FALSE", "\n"'
> TRUE
> 
> Why?

perldoc perlfaq4 explains some of the crap about working with floats.

In general you shouldn't expect either to work reliably.

If you would like working with more precise values use bignum, bigrat,
and so forth, or implement it all in integers, working with the smallest
unit possible (like 1000 agoroths == 10 nis, and 1010 == 10.10).

Good luck!

-- 
 ()  Yuval Kogman <nothingmuch at woobling.org> 0xEBD27418  perl hacker &
 /\  kung foo master: /me climbs a brick wall with his fingers: neeyah!



More information about the Perl mailing list