From: Eleanor McHugh Date: 2008-07-02T23:06:06+09:00 Subject: Re: Arithmetic oddity On 2 Jul 2008, at 15:01, Robert Klemme wrote: > 2008/7/2 Minh Tran : >> I tried with >> >> s = l.map {|e| (e**2).to_s.to_f} >> >> instead of >> >> s = l.map {|e| e**2} >> >> and it now works. > > But it works only accidentally! This is likely to break soon again. > >> It doesn't look very elegant though to need such kind of hacking to >> make >> it base operator to work as expected. > > No, no, no! The operator works as expected. There is even an IEEE > standard defining how floating point math has to behave. You must > *never* rely on == when doing float math. In this case you rather > need to do either of these > > - resort to decimal math with BigDecimal > > - define equality as a max difference ("epsilon") between two float > values and test that Phrased much better than my replies :) Ellie Eleanor McHugh Games With Brains http://slides.games-with-brains.net ---- raise ArgumentError unless @reality.responds_to? :reason