From: Christopher Dicely Date: 2011-08-14T09:56:02+09:00 Subject: Re: Why this? On Sat, Aug 13, 2011 at 12:28 PM, Николай wrote: > > > -------- Original Message -------- > Subject:        Why this? > Date:   Sat, 13 Aug 2011 22:20:04 +0300 > From:   Николай > 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 > a.to_f == b                              #=>  false > 125.0 == 125                          #=>  true > 125.0.to_f == 125                   #=>  true The second result is the version of "inspect" bundled with your ruby installation misleading you. Ruby 1.9.2p180, via RubyInstaller, Win7 32-bit gives me: irb(main):001:0> a=(10**2 + 5**2) => 125 irb(main):002:0> b=Math.hypot(10,5)**2 => 125.00000000000001 IronRuby 1.1 gives me behavior that looks like what you see, but a quick test shows that that "125.0" inspect value is skin deep: irb(main):001:0> b=Math.hypot(10,5)**2 => 125.0 irb(main):002:0> b<=>125.0 => 1 irb(main):003:0> b==125.00000000000001 => true More generally, you are generally in deep trouble when you count on floating point calculations producing exact results.