summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2017-11-09 17:53:39 -0500
committerBen Gamari <ben@smart-cactus.org>2017-11-09 18:31:21 -0500
commit5834da4872877736eefb85daedaf7b137ae702a1 (patch)
treee00dd15211af5e311ff29ba7a05a167f3d7c4b8e
parentc59d6da8639fd88919090b29cf4e76c4d0d8bbde (diff)
downloadhaskell-5834da4872877736eefb85daedaf7b137ae702a1.tar.gz
base: Fix #14425
Test Plan: Validate Reviewers: hvr Subscribers: rwbarton, thomie GHC Trac Issues: #14425 Differential Revision: https://phabricator.haskell.org/D4167
-rw-r--r--libraries/base/Data/Ratio.hs4
-rw-r--r--libraries/base/tests/all.T2
2 files changed, 4 insertions, 2 deletions
diff --git a/libraries/base/Data/Ratio.hs b/libraries/base/Data/Ratio.hs
index 8d195063a5..946824fec2 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 7839076b57..06c7350026 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, [''])