I think it may be best to regard floats conceptually as reals. 
Mathematics tells us that almost all reals are irrational and almost 
none of them are rational. That means that almost every comparison of 
the form x == 2.85 (where the LHS is real and the RHS is rational) will 
be false.

Therefore the best guidance, often seen in Programming 101, is "Never 
compare floats for equality!" The only numbers that are guaranteed to be 
exact in a computer are integers, so one should only compare integers 
for equality.

Of course in a computer we're always dealing with rational numbers (due 
to finite precision) so this isn't quite true, but it's a good guiding 
principle.

Using a fuzzy comparison dressed up as an exact comparison is a bad idea 
IMHO. If you want to do that, do it explicitly, something like 
assert_in_delta.

In many years of numerical simulation work (Fortran, C, Perl, ...) I've 
never had to compare floats for equality. There has always been a better 
way to do the job.

Dave

-- 
Posted via http://www.ruby-forum.com/.