[commit: ghc] master: base: Fix #14425 (5834da4)

git at git.haskell.org git at git.haskell.org
Thu Nov 9 23:35:07 UTC 2017


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

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

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

commit 5834da4872877736eefb85daedaf7b137ae702a1
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Thu Nov 9 17:53:39 2017 -0500

    base: Fix #14425
    
    Test Plan: Validate
    
    Reviewers: hvr
    
    Subscribers: rwbarton, thomie
    
    GHC Trac Issues: #14425
    
    Differential Revision: https://phabricator.haskell.org/D4167


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

5834da4872877736eefb85daedaf7b137ae702a1
 libraries/base/Data/Ratio.hs | 4 +++-
 libraries/base/tests/all.T   | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libraries/base/Data/Ratio.hs b/libraries/base/Data/Ratio.hs
index 8d19506..946824f 100644
--- a/libraries/base/Data/Ratio.hs
+++ b/libraries/base/Data/Ratio.hs
@@ -49,7 +49,9 @@ import GHC.Real         -- The basic defns for Ratio
 
 approxRational :: (RealFrac a) => a -> a -> Rational
 approxRational rat eps =
-    simplest (rat-eps) (rat+eps)
+    -- We convert rat and eps to rational *before* subtracting/adding since
+    -- otherwise we may overflow. This was the cause of #14425.
+    simplest (toRational rat - toRational eps) (toRational rat + toRational eps)
   where
     simplest x y
       | y < x      =  simplest y x
diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T
index 7839076..06c7350 100644
--- a/libraries/base/tests/all.T
+++ b/libraries/base/tests/all.T
@@ -221,4 +221,4 @@ test('T3474',
      [stats_num_field('max_bytes_used', [ (wordsize(64), 44504, 5) ]),
       only_ways(['normal'])],
      compile_and_run, ['-O'])
-test('T14425', expect_broken(14425), compile_and_run, [''])
+test('T14425', normal, compile_and_run, [''])



More information about the ghc-commits mailing list