From d58d44f30b8a39a40716903df645767b12445b09 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Thu, 28 Feb 2013 11:05:45 +0100 Subject: [PATCH] Switch Attoparsec parser from double to rational MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Iustin Pop <iustin@google.com> Reviewed-by: Michele Tartara <mtartara@google.com> --- src/Ganeti/Hypervisor/Xen/XmParser.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ganeti/Hypervisor/Xen/XmParser.hs b/src/Ganeti/Hypervisor/Xen/XmParser.hs index a5459f29d..c24d11147 100644 --- a/src/Ganeti/Hypervisor/Xen/XmParser.hs +++ b/src/Ganeti/Hypervisor/Xen/XmParser.hs @@ -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 -- GitLab