From: Minh Tran Date: 2008-07-02T22:25:31+09:00 Subject: Re: Arithmetic oddity 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. Eleanor McHugh wrote: > On 2 Jul 2008, at 13:48, Minh Tran wrote: >> It still look odd as the value in s[2] is 2.0 which doesn't seems to >> have any rounding problem. >> >> In any case is there any workaround to fix get the condition as true ? > > Floating point representations are in many cases (such as irrational > numbers like square root of 2) only approximations to a given value, > you therefore have to test that the value is accurate to a given > precision (number of significant digits). For example, given: > > x = (1.0 + 1.0) ** 0.5 > > you could write your test as: > > (x ** 2.0).between?(1.9999, 2.0001) > > > Ellie > > Eleanor McHugh > Games With Brains > http://slides.games-with-brains.net > ---- > raise ArgumentError unless @reality.responds_to? :reason -- Posted via http://www.ruby-forum.com/.