From: Pit Capitain Date: 2006-07-07T16:47:42+09:00 Subject: Re: Float#==. Legacy? Matthew Smillie schrieb: > On Jul 6, 2006, at 16:39, 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. > > This is something that I'd refer to as a code smell rather than an > error. Floating point numbers can represent and operate on lots of > actual numbers with no loss of precision, for a trivial example: 2.0 + > 2.0 will always equal exactly 4.0, and any other result from that > operation, no matter how small the difference, would be an error. You have to know a lot about the implementation of floating point numbers in order to be able to predict the result of seemingly trivial examples: 0.1 + 0.1 == 0.2 # => true 0.1 + 0.2 == 0.3 # => false The only really trivial examples I can think of use small integers. If I'm working with those numbers, I wouldn't use floats, though. Regards, Pit