From: Joel VanderWerf Date: 2009-06-06T12:09:17+09:00 Subject: Re: rounding errors? Pascal J. Bourguignon wrote: > Pete Hodgson writes: > >> :~$ ruby -e "p ((0.29)*100).to_i" >> 28 >> >> Really?! I know that digital storage of floating point numbers can lead >> to things like this, but this one seems a little extreme to me. > > You may try a true Lisp instead of a Matzacred Lisp: > > $ clisp -q -norc -x '(values (truncate (* 0.29 100)))' > 29 > There's nothing strange here, just IEEE floats, which don't represent every decimal float: irb(main):001:0> (0.29)*100 => 29.0 irb(main):002:0> ((0.29)*100).to_i => 28 irb(main):003:0> ((0.29)*100).round => 29 irb(main):004:0> ((0.29)*100).floor => 28 irb(main):006:0> "%20.18f" % ((0.29)*100) => "28.999999999999996447" irb(main):007:0> "%20.18f" % 0.29 => "0.289999999999999980" -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407