On Sat, Aug 13, 2011 at 9:28 PM, ڧܧݧѧ<Godsent / mail.ru> wrote:

>
>
> -------- Original Message --------
> Subject:        Why this?
> Date:   Sat, 13 Aug 2011 22:20:04 +0300
> From:   ڧܧݧѧ <godsent / tut.by>
> To:     ruby-talk / ruby-lang.org
>
>
>
> Hallow, can anybody explain me that?
> a = (10**2 + 5**2)                  #=>  125
> b = Math.hypot(10, 5)**2        #=>  125.0
>


> a == b                                     #=>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 ==
b.round


> a.to_f == b                              #=>  false
>

Same as above.


> 125.0 == 125                          #=>  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 same
type).


> 125.0.to_f == 125                   #=>  true
>
>
Same as above.