From: bbense+comp.lang.ruby.Dec.11.02@... Date: 2002-12-12T04:20:46+09:00 Subject: Re: warnings -w -----BEGIN PGP SIGNED MESSAGE----- In article <3DF5DC0A.8010106@spellmanhv.co.uk>, Robert McGovern wrote: >>>>>(2.4/0.2).to_i >> >> D> => 11 >> >> Float#to_i is the same than Float#truncate >> >> pigeon% ruby -e 'p ((2.4/0.2).truncate)' >> 11 >> pigeon% >> >> pigeon% ruby -e 'p ((2.4/0.2).floor)' >> 11 >> pigeon% >> >> pigeon% ruby -e 'p ((2.4/0.2).ceil)' >> 12 >> pigeon% >> >> pigeon% ruby -e 'p ((2.4/0.2).round)' >> 12 >> pigeon% > >As 2.4 /0.2 is fundementally 12, why should (2.4/0.2).floor or .truncate >give 11? - - It's 12 on the real number line. It's something quite different in your computers implementation of IEEE floating point standards. > >The method should be called on the result of the 2.4 / 0.2 calculation >which is 12 or 12.0 and therefore the result should always be 12. > - - This is a fact of life in doing floating point arithmetic on a computer and has absolutely nothing to do with Ruby. I suggest that you goggle IEEE floating point and learn some of the basics of floating point programming. - - Booker C. Bense -----BEGIN PGP SIGNATURE----- Version: 2.6.2 iQCVAwUBPfeKv2TWTAjn5N/lAQEi/QQApTBWp9oEgYdaqxbGg7HHsvocvf/j99EH gDN1suhajQIyeSiDb8KIf0ld82HP/Cofhy0jXi2kWA9aSRZ6OwhtKUb2SkLoNyH2 KrUQLqT1gx7xkArz8ipUq1Lgnd0hReF7tFN/TtBX4cesgZux06Bn1IaLE18B1nyp OE3pHVJHcAo= =sIRU -----END PGP SIGNATURE-----