[Haskell-cafe] Re: Defaulting to Rational [was: Number overflow]
bos at serpentine.com
Thu Jul 12 09:27:08 EDT 2007
> In a sense, the instances of Eq and Ord for floating point numbers are
> wrong. What about rolling new classes for approximate equality and ordering?
> class ApproxEq a where
> (≈) :: a -> a -> Bool -- almost equal to
The problems with this approach are generally worse than those with Eq,
whose shortcomings are at least well defined and widely understood.
You need to choose an epsilon of the right magnitude for the numbers
you're working with, and the epsilon is likely to be domain-specific.
The signedness of the numbers you're comparing is also a factor: should
the behaviour be different if they have different signs? Also, since
these aren't equivalence relations, ApproxEq has the weird property that
a ≈ b and b ≈ c does not imply a ≈ c; ApproxOrd suffers from the same
More information about the Haskell-Cafe