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

Warren Harris warrensomebody at gmail.com
Tue Jun 5 18:12:26 CEST 2012


The double parser provided by Data.Attoparsec.ByteString.Char8 looses precision around the 13-15th decimal place (http://hackage.haskell.org/packages/archive/attoparsec/0.10.2.0/doc/html/Data-Attoparsec-ByteString-Char8.html#v:double). Unfortunately this reeks havoc with my attempts to write a quickCheck test that validates print-read equivalence for a program that uses Aeson. I have tried compensating for this round-off error in my quickCheck generator using a function like this:

roundDouble :: Double -> Double
roundDouble d = let Right v = A8.parseOnly A8.double (C.pack (show d)) in v

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. 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,

Warren


More information about the Haskell-Cafe mailing list