From: Axel Etzold Date: 2008-10-28T05:13:32+09:00 Subject: Re: float equality -------- Original-Nachricht -------- > Datum: Tue, 28 Oct 2008 04:31:06 +0900 > Von: "guille lists" > An: ruby-talk@ruby-lang.org > Betreff: Re: float equality > Thanks a lot for the answers and references, and sorry for not having > check deeper on google > (http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/9655). > > So I guess that if one wants to work for example with float numbers in > the range [0,1], the best way to do it is by normalising from an > integer interval depending on the precision you want, say [0,100] for > two decimal digits precision, and so on. Is there any other better > approach? Does the use of BigDecimal impose a severe penalty on > performance? > > > guille Dear guille, you could use some approximate equality check: class Float def approx_equal?(other,threshold) if (self-other).abs