From: Martin DeMello Date: 2006-07-07T22:26:33+09:00 Subject: Re: Float#==. Legacy? On 7/6/06, Guillaume Marcais wrote: > As far as my experience goes, using Float#== is always an error. Float > should be compared within epsilon because of errors, etc. etc. But the > question is: why keep Float#== if it is basically useless? Why not have > Float#== be defined in the core by: > > class Float; def ==(o); ((o - self).abs < 0.0000001); end; end > > (Most likely with 0.0000001 be a parameter of the Float class so it can > be changed at runtime.) Is the current implementation of Float#== > legacy from C (and pretty much every other language I can think of)? > > It would make the behavior of Float more natural to humans and should > not break much, given the uselessness of today's Float#==. This is ugly, because Float#== is a two-argument method that you're faking with one argument and one global constant. An array argument might be a nice piece of syntactic sugar, though I'd still prefer to overload =~ instead, e.g. a =~ [b, epsilon] with a =~ b defaulting to Float::EPSILON. Also, note that your method definition needs to be def =~ (o); ((o - self)/o).abs <= EPSILON; end you want relative, not absolute, error margins. martin