Commit d58d44f3 authored by Iustin Pop's avatar Iustin Pop
Browse files

Switch Attoparsec parser from double to rational



According to the documentation, “This function is almost ten times
faster than rational, but is slightly less accurate. For 94.2% of
numbers, this function and rational give identical results, but for
the remaining 5.8%, this function loses precision around the 15th
decimal place. For 0.001% of numbers, this function will lose
precision at the 13th or 14th decimal place.”. What happens is that
for our tests, it can happen that “Attoparsec.double (show a_double)”
is quite different from “a_double”, such that we have much more than
1e-12 absolute difference.

Since our xm lists should not be too big, I think switching to
rational is better. Next patch also changes the way we compare
doubles, so maybe this patch is not really needed…
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent 1fe0e999
......@@ -59,8 +59,8 @@ lispConfigParser =
where listConfigP = LCList <$> (A.char '(' *> liftA2 (++)
(many middleP)
(((:[]) <$> finalP) <|> (rparen *> pure [])))
doubleP = LCDouble <$> A.double <* A.skipSpace <* A.endOfInput
innerDoubleP = LCDouble <$> A.double
doubleP = LCDouble <$> A.rational <* A.skipSpace <* A.endOfInput
innerDoubleP = LCDouble <$> A.rational
stringP = LCString . unpack <$> A.takeWhile1 (not . (\c -> isSpace c
|| c `elem` "()"))
wspace = AC.many1 A.space
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment