[commit: ghc] ghc-8.6: base: showEFloat: Handle negative precisions the same of zero precision (2116932)

git at git.haskell.org git at git.haskell.org
Sun Sep 16 20:26:51 UTC 2018


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

On branch  : ghc-8.6
Link       : http://ghc.haskell.org/trac/ghc/changeset/2116932ef55fe2f11e04f9a9e593bc73a2e96680/ghc

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

commit 2116932ef55fe2f11e04f9a9e593bc73a2e96680
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
    
    (cherry picked from commit e71e341f87c055ecc01f85ddd8d7a2094dfa8e9a)


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

2116932ef55fe2f11e04f9a9e593bc73a2e96680
 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 26a5987..8790a92 100644
--- a/libraries/base/GHC/Float.hs
+++ b/libraries/base/GHC/Float.hs
@@ -729,16 +729,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