OTHER TIPS
Depending on your application and what your floating point values are actually representing, it might make sense to convert them to Rationals with a given precision. Then direct comparisons will always behave correctly since Rationals are just two integers.
For instance, if you know you're dealing with US currency amounts, storing them as amount.to_r.round(2)
allows for exact comparisons for equality.
Just a thought... not all non-integer values need to be inexactly-represented floats
you may also need a relative tolerance / delta calculation
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow