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.
This commit is contained in:
Iavor Diatchki 2020-07-14 10:47:19 -07:00
parent 1dd4bbd22c
commit 6e412ed32e
2 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -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-----------------------------------------------------------------"