Commit a59bf178 authored by Daniel Fischer's avatar Daniel Fischer

FIX #4336

Avoid superfluous gcd calculation in recip for Ratio a because numerator
and denominator are known to be coprime.
parent 834b9cfa
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment