Commit e71e341f authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

base: showEFloat: Handle negative precisions the same of zero precision

Test Plan: Validate

Reviewers: hvr, alpmestan

Reviewed By: alpmestan

Subscribers: rwbarton, carter

GHC Trac Issues: #15509

Differential Revision: https://phabricator.haskell.org/D5083
parent 5f5898a5
......@@ -721,16 +721,18 @@ formatRealFloatAlt fmt decs alt x
[d] -> d : ".0e" ++ show_e'
(d:ds') -> d : '.' : ds' ++ "e" ++ show_e'
[] -> errorWithoutStackTrace "formatRealFloat/doFmt/FFExponent: []"
Just 0 ->
Just d | d <= 0 ->
-- handle this case specifically since we need to omit the
-- decimal point as well (#15115)
-- decimal point as well (#15115).
-- Note that this handles negative precisions as well for consistency
-- (see #15509).
case is of
[0] -> "0e0"
_ ->
let
(ei,is') = roundTo base 1 is
d:_ = map intToDigit (if ei > 0 then init is' else is')
in d : 'e' : show (e-1+ei)
n:_ = map intToDigit (if ei > 0 then init is' else is')
in n : 'e' : show (e-1+ei)
Just dec ->
let dec' = max dec 1 in
case is of
......
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