From: Eleanor McHugh Date: 2008-07-02T21:05:08+09:00 Subject: Re: Arithmetic oddity On 2 Jul 2008, at 12:30, Minh Tran wrote: >>> l = [1.0, 1.0, 2.0**0.5] > => [1.0, 1.0, 1.4142135623731] >>> s = l.map {|e| e**2} > => [1.0, 1.0, 2.0] >>> puts 'foo' if s[2] == s[1] + s[0] > => nil >>> puts 'foo' if 2.0 == 1.0 + 1.0 > foo > => nil > > Does anyone know why s[2] == s[1] + s[0] is false ? If you check in IRB you'll find that ((2.0 ** 0.5) ** 2.0) == 2.0 returns false. That will be due to rounding errors in performing the sequence of floating point operations. Ellie Eleanor McHugh Games With Brains http://slides.games-with-brains.net ---- raise ArgumentError unless @reality.responds_to? :reason