From b2f76d1e62488565e470ffc24551090c83f66ee5 Mon Sep 17 00:00:00 2001 From: Daniel Fischer Date: Thu, 21 Oct 2010 09:32:46 +0000 Subject: [PATCH] FIX #4336 Avoid superfluous gcd calculation in recip for Ratio a because numerator and denominator are known to be coprime. --- GHC/Real.lhs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/GHC/Real.lhs b/GHC/Real.lhs index 971f276..4c2ed45 100644 --- a/GHC/Real.lhs +++ b/GHC/Real.lhs @@ -331,7 +331,10 @@ instance (Integral a) => Num (Ratio a) where instance (Integral a) => Fractional (Ratio a) where {-# SPECIALIZE instance Fractional Rational #-} (x:%y) / (x':%y') = (x*y') % (y*x') - recip (x:%y) = y % x + recip (0:%_) = error "Ratio.%: zero denominator" + recip (x:%y) + | x < 0 = negate y :% negate x + | otherwise = y :% x fromRational (x:%y) = fromInteger x :% fromInteger y instance (Integral a) => Real (Ratio a) where -- 1.7.10.4