It you're interested in some reading about floating point then =
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html is worth =
looking at.

Mike

On 2011-12-16, at 7:20 AM, Peter Vandenabeele wrote:

> On Fri, Dec 16, 2011 at 1:09 PM, Vimal R. <email2vimalraj / gmail.com> =
wrote:
>=20
>> Hi,
>>=20
>> I don't face this problem.
>>=20
>> When I follow the same code in my machine, I get proper result for
>> 4.9 x 5.9 =3D 28.91
>> 3.9 x 3.9 =3D 15.21
>>=20
>=20
> You most probably _do_ face the problem, but don't see it because the
> _presentation_ of the result masks the small remainder errors. And =
what's
> worse, the result might be dependent on the position of the moon =
(sorry,
> joke, but the result will differ, based on the exact Ruby version, CPU
> etc. that is used when the code is ran).
>=20
> On ruby 1.9.3
>=20
> peterv@e6500:~$ irb
> ruby-1.9.3-p0 :001 > 4.9 * 5.9
> =3D> 28.910000000000004
> ruby-1.9.3-p0 :002 > "%35.30f"%(4.9 * 5.9)
> =3D> "  28.910000000000003694822225952521"
>=20
>=20
> On ruby 1.8.7
>=20
> peterv@e6500:~$ rvm use 1.8.7-p330
> Using /home/peterv/.rvm/gems/ruby-1.8.7-p330
> peterv@e6500:~$ irb
> no such file to load -- wirble
> ruby-1.8.7-p330 :001 > 4.9 * 5.9
> =3D> 28.91
> ruby-1.8.7-p330 :002 > "%35.30f"%(4.9 * 5.9)
> =3D> "  28.910000000000003694822225952521"
>=20
> HTH,
>=20
> Peter
>=20
> --=20
> Peter Vandenabeele
> http://twitter.com/peter_v
> http://rails.vandenabeele.com

--=20

Mike Stok <mike / stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.