From 5834da4872877736eefb85daedaf7b137ae702a1 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Thu, 9 Nov 2017 17:53:39 -0500 Subject: base: Fix #14425 Test Plan: Validate Reviewers: hvr Subscribers: rwbarton, thomie GHC Trac Issues: #14425 Differential Revision: https://phabricator.haskell.org/D4167 --- 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 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, ['']) -- cgit v1.2.1