[commit: ghc] master: base: showEFloat: Handle negative precisions the same of zero precision (e71e341)

git at git.haskell.org git at git.haskell.org
Thu Sep 13 23:07:44 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/e71e341f87c055ecc01f85ddd8d7a2094dfa8e9a/ghc

>---------------------------------------------------------------

commit e71e341f87c055ecc01f85ddd8d7a2094dfa8e9a
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Thu Sep 13 17:09:56 2018 -0400

    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


>---------------------------------------------------------------

e71e341f87c055ecc01f85ddd8d7a2094dfa8e9a
 libraries/base/GHC/Float.hs | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libraries/base/GHC/Float.hs b/libraries/base/GHC/Float.hs
index 693a209..9296978 100644
--- a/libraries/base/GHC/Float.hs
+++ b/libraries/base/GHC/Float.hs
@@ -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



More information about the ghc-commits mailing list