From: John-John Tedro Date: 2011-08-14T06:02:12+09:00 Subject: Re: Why this? --0016e650976ef5b8d004aa695786 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sat, Aug 13, 2011 at 9:28 PM, =D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9= wrote: > > > -------- Original Message -------- > Subject: Why this? > Date: Sat, 13 Aug 2011 22:20:04 +0300 > From: =D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9 > To: ruby-talk@ruby-lang.org > > > > Hallow, can anybody explain me that? > a =3D (10**2 + 5**2) #=3D> 125 > b =3D Math.hypot(10, 5)**2 #=3D> 125.0 > > a =3D=3D b #=3D>false > http://ruby-doc.org/core/classes/Fixnum.html#M001090 They are not numerically equal. b is not exactly 125.0, I'm not into details about ruby's float implementation, but the result simply isn't 100% accurate. Try a.to_f =3D= =3D b.round > a.to_f =3D=3D b #=3D> false > Same as above. > 125.0 =3D=3D 125 #=3D> true > http://www.ruby-doc.org/core/classes/Float.html#M000127 The 125.0 declaration is accurate, so numerical equality is true. As the documentation says, this is not an eql? check (i.e. does not have to be sam= e type). > 125.0.to_f =3D=3D 125 #=3D> true > > Same as above. --0016e650976ef5b8d004aa695786--