From 6e412ed32e1c7a3e07dd7646e03e0046cd038326 Mon Sep 17 00:00:00 2001 From: Iavor Diatchki Date: Tue, 14 Jul 2020 10:47:19 -0700 Subject: [PATCH] A hack to always print .0 for non base 10 numbers. This helps with copy-pasting values, as non base 10 literals are not overloaded. --- src/Cryptol/Eval/Concrete/FloatHelpers.hs | 10 +++++++++- tests/regression/float.icry.stdout | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Cryptol/Eval/Concrete/FloatHelpers.hs b/src/Cryptol/Eval/Concrete/FloatHelpers.hs index 954d3118..c7f33888 100644 --- a/src/Cryptol/Eval/Concrete/FloatHelpers.hs +++ b/src/Cryptol/Eval/Concrete/FloatHelpers.hs @@ -73,7 +73,7 @@ fpPP opts bf = case bfSign num of Nothing -> "fpNaN" Just s - | bfIsFinite num -> text (bfToString base fmt num) + | bfIsFinite num -> text hacStr | otherwise -> case s of Pos -> "fpPosInf" @@ -89,6 +89,7 @@ fpPP opts bf = AutoExponent -> f ForceExponent -> f <> forceExp + str = bfToString base fmt num fmt = addPrefix <> showRnd NearEven <> case useFPFormat opts of FloatFree e -> withExp e $ showFreeMin @@ -96,6 +97,13 @@ fpPP opts bf = FloatFixed n e -> withExp e $ showFixed $ fromIntegral n FloatFrac n -> showFrac $ fromIntegral n + -- non-base 10 literals are not overloaded so we add an explicit + -- .0 if one is not present. + hacStr + | base == 10 || elem '.' str = str + | otherwise = case break (== 'p') str of + (xs,ys) -> xs ++ ".0" ++ ys + -- | Make a literal diff --git a/tests/regression/float.icry.stdout b/tests/regression/float.icry.stdout index 289ec167..e462f086 100644 --- a/tests/regression/float.icry.stdout +++ b/tests/regression/float.icry.stdout @@ -32,7 +32,7 @@ Specifies the format to use when showing floating point numbers: 0x0.6 0x1.234p4 0x12.3 -0x12 +0x12.0 0x1.2p4 "-- Float Type-----------------------------------------------------------------"