From: Stefan Lang Date: 2008-08-05T05:04:27+09:00 Subject: Re: Whose fault is my problem? 2008/8/4 Daniel Moore : > On Mon, Aug 4, 2008 at 7:38 AM, The Podman wrote: > >> * Float == Float does not perform any delta difference checking. In a >> way, this is expected. In another way, it's not. > > If you don't like the == method of Float just crack it open and change it: > > a = 12.60000000000001 > b = 12.59999999999999 > > puts a > puts b > > puts a == b # => false > > class Float > def ==(other) > fuzz = 1.0E-10 > max = [self.abs, other.abs].max > ( self - other ).abs / max < fuzz > end > end > > puts a == b # => true > > I would only recommend doing this for your tests though, ... I think that's a bad strategy. If he has == comparisons of Float in his code where a delta check would be the right thing, this would hide it from the tests. Stefan