From: Eleanor McHugh Date: 2008-07-02T22:57:15+09:00 Subject: Re: Arithmetic oddity On 2 Jul 2008, at 14:25, Minh Tran wrote: > 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. > > It doesn't look very elegant though to need such kind of hacking to > make > it base operator to work as expected. And that method also imposes considerable runtime cost. As I said, use a comparison such as (2.0).between?(1.99999, 2.00001) as that's: a. computationally much less expensive; b. what a floating-point '==' actually means. Also you should probably read http://en.wikipedia.org/wiki/Floating_point and then do some further research into floating point number representations to gain some deeper insight into what is actually meant by 2.0 when it's converted into binary format. It may inspire you to more elegant ways of solving whatever problem it is that you're working on. Ellie Eleanor McHugh Games With Brains http://slides.games-with-brains.net ---- raise ArgumentError unless @reality.responds_to? :reason