--- Real.lhs.orig 2007-04-25 13:17:00.000000000 -0400 +++ Real.lhs 2007-07-21 14:18:21.000000000 -0400 @@ -301,14 +301,26 @@ \begin{code} instance (Integral a) => Ord (Ratio a) where {-# SPECIALIZE instance Ord Rational #-} - (x:%y) <= (x':%y') = x * y' <= x' * y - (x:%y) < (x':%y') = x * y' < x' * y + (x:%y) <= (x':%y') = toInteger x * toInteger y' <= toInteger x' * toInteger y + (x:%y) < (x':%y') = toInteger x * toInteger y' < toInteger x' * toInteger y instance (Integral a) => Num (Ratio a) where {-# SPECIALIZE instance Num Rational #-} - (x:%y) + (x':%y') = reduce (x*y' + x'*y) (y*y') - (x:%y) - (x':%y') = reduce (x*y' - x'*y) (y*y') - (x:%y) * (x':%y') = reduce (x * x') (y * y') + (x:%y) + (x':%y') = fromInteger xi'' % fromInteger yi'' where + xi = toInteger x + yi = toInteger y + xi' = toInteger x' + yi' = toInteger y' + xi'' :% yi'' = (xi * yi' + xi' * yi) % (yi * yi') + (x:%y) - (x':%y') = fromInteger xi'' % fromInteger yi'' where + xi = toInteger x + yi = toInteger y + xi' = toInteger x' + yi' = toInteger y' + xi'' :% yi'' = (xi * yi' - xi' * yi) % (yi * yi') + (x:%y) * (x':%y') = (a * a') % (b * b') where + a :% b' = reduce x y' + a' :% b = reduce x' y negate (x:%y) = (-x) :% y abs (x:%y) = abs x :% y signum (x:%_) = signum x :% 1 @@ -316,9 +328,11 @@ instance (Integral a) => Fractional (Ratio a) where {-# SPECIALIZE instance Fractional Rational #-} - (x:%y) / (x':%y') = (x*y') % (y*x') + (x:%y) / (x':%y') = (a * b') % (b * a') where + a :% a' = reduce x x' + b' :% b = reduce y' y recip (x:%y) = y % x - fromRational (x:%y) = fromInteger x :% fromInteger y + fromRational (x:%y) = fromInteger x % fromInteger y instance (Integral a) => Real (Ratio a) where {-# SPECIALIZE instance Real Rational #-}