[Haskell-cafe] attoparsec double precision, quickCheck and aeson

Johan Tibell johan.tibell at gmail.com
Tue Jun 5 18:38:54 CEST 2012

On Tue, Jun 5, 2012 at 9:12 AM, Warren Harris <warrensomebody at gmail.com> wrote:
> which helps in many cases, but for some the parsing seems bi-stable, alternating between two imprecise double values and causing the test to fail.

You want to perform your test as

    d1 - d2 < epsilon

where epsilon is derived from the relative error you're willing to
accept (e.g. 0.01% error.) You can't use an absolute epsilon because
if you pick e.g. epsilon = 0.00001 but your input are also very small,
you'll end up accepting a big relative error. Comparing floating
points values for equality is asking for trouble.

> I was wondering if anyone could suggest a better work-around for this problem, or explain why Attoparsec's double parser can't be isomorphic to haskell's. Thanks,

I think attoparsec uses a slightly less exact but much much faster
double parser. I believe it's described in the attoparsec haddock docs

-- Johan

More information about the Haskell-Cafe mailing list