[Haskell-cafe] Working around floating-point inaccuracies

Frank Staals frank at fstaals.net
Tue Aug 7 16:25:42 UTC 2018


Michail Pevnev <mpevnev at gmail.com> writes:

> Hello everyone!
>
> For a library I write at the moment, I made a class for approximate
> geometric equality comparisons (and dubbed it `ApproxEq`). It's not a
> very lawful class, but there is one invariant that should hold
> absolutely always - if two entities coincide but have different
> representations, they should compare "equal".

The approximate-equality package
(https://hackage.haskell.org/package/approximate-equality) provides a
nicer way of doing that IMO. I've used that a few times when I needed an
aprpimxate Floating type. Generally I think it is just better to use
exact number types, like Rational, when implementing geometric
algorithms though. That is what I tend to use in hgeometry as well (
that quite often a Fractional constraint is sufficient anyway).

--

- Frank


More information about the Haskell-Cafe mailing list