Quoting jzimmek <[email protected]>:
> 
> some of my tests failed when comparing two floats.
> 
> the comparison of:
> 
> 1.1035 == 1.0035 + 0.1
> 
> evaluates to false - i do not really understand why.
> 
> must depend on the value range, because
> 
> 1.103 == 1.003 + 0.1
> 

In general, exact comparisons of floating point numbers is a bad idea.  A
better idea is something along the lines of:

(value1 - value2).abs <= epsilon

epsilon may be a fixed value of a fraction of the values, maybe

epsilon = (value1 + value2) / 100

i.e. 1/50 the average of the two.  The best solution depends on the particular
problem.

Jeffrey

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to