Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Data/Text/Lazy/Builder/RealFloat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ formatRealFloat fmt decs x
[d] -> singleton d <> ".0e" <> show_e'
(d:ds') -> singleton d <> singleton '.' <> fromString ds' <> singleton 'e' <> show_e'
[] -> error "formatRealFloat/doFmt/Exponent/Nothing: []"
Just dec | dec <= 0 ->
-- No decimals: leave out the period too, as showEFloat does (gh-231).
case is of
[0] -> "0e0"
_ ->
let (ei,is') = roundTo 1 is
in case map i2d (if ei > 0 then init is' else is') of
[] -> error "formatRealFloat/doFmt/Exponent/Just 0: []"
(d:_) -> singleton d <> singleton 'e' <> decimal (e-1+ei)
Just dec ->
let dec' = max dec 1 in
case is of
Expand Down
10 changes: 6 additions & 4 deletions tests/Tests/Properties/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ tb_realfloat_float (a::Float) = tb_realfloat a
tb_realfloat_double (a::Double) = tb_realfloat a

showFloat :: (RealFloat a) => TB.FPFormat -> Maybe Int -> a -> ShowS
showFloat TB.Exponent (Just 0) = showEFloat (Just 1) -- see gh-231
showFloat TB.Exponent p = showEFloat p
showFloat TB.Fixed p = showFFloat p
showFloat TB.Generic p = showGFloat p
Expand All @@ -93,10 +92,13 @@ tb_formatRealFloat a fmt prec = cond ==>
TB.fromString (showFloat fmt p a "")
where p = precision a prec
cond = case (p,fmt) of
#if MIN_VERSION_base(4,12,0)
(Just 0, TB.Generic) -> False -- skipping due to gh-231
#if !MIN_VERSION_base(4,12,0)
-- Before base-4.12, showEFloat showed one decimal for
-- Just 0 (GHC#15115, gh-231).
(Just 0, TB.Exponent) -> False
(Just 0, TB.Generic) -> False
#endif
_ -> True
_ -> True

tb_formatRealFloat_float (a::Float) = tb_formatRealFloat a
tb_formatRealFloat_double (a::Double) = tb_formatRealFloat a
Expand Down