Ticket #1517: patch.txt

File patch.txt, 1.8 KB (added by dbenbenn@…, 10 years ago)

Patch to (mostly) fix the problem

Line
1--- Real.lhs.orig       2007-04-25 13:17:00.000000000 -0400
2+++ Real.lhs    2007-07-21 14:18:21.000000000 -0400
3@@ -301,14 +301,26 @@
4 \begin{code}
5 instance  (Integral a) => Ord (Ratio a)  where
6     {-# SPECIALIZE instance Ord Rational #-}
7-    (x:%y) <= (x':%y') =  x * y' <= x' * y
8-    (x:%y) <  (x':%y') =  x * y' <  x' * y
9+    (x:%y) <= (x':%y') =  toInteger x * toInteger y' <= toInteger x' * toInteger y
10+    (x:%y) < (x':%y')  =  toInteger x * toInteger y' < toInteger x' * toInteger y
11
12 instance  (Integral a) => Num (Ratio a)  where
13     {-# SPECIALIZE instance Num Rational #-}
14-    (x:%y) + (x':%y')  =  reduce (x*y' + x'*y) (y*y')
15-    (x:%y) - (x':%y')  =  reduce (x*y' - x'*y) (y*y')
16-    (x:%y) * (x':%y')  =  reduce (x * x') (y * y')
17+    (x:%y) + (x':%y')  =  fromInteger xi'' % fromInteger yi'' where
18+       xi = toInteger x
19+       yi = toInteger y
20+       xi' = toInteger x'
21+       yi' = toInteger y'
22+       xi'' :% yi'' = (xi * yi' + xi' * yi) % (yi * yi')
23+    (x:%y) - (x':%y')  =  fromInteger xi'' % fromInteger yi'' where
24+       xi = toInteger x
25+       yi = toInteger y
26+       xi' = toInteger x'
27+       yi' = toInteger y'
28+       xi'' :% yi'' = (xi * yi' - xi' * yi) % (yi * yi')
29+    (x:%y) * (x':%y')  =  (a * a') % (b * b') where
30+        a :% b' = reduce x y'
31+        a' :% b = reduce x' y
32     negate (x:%y)      =  (-x) :% y
33     abs (x:%y)         =  abs x :% y
34     signum (x:%_)      =  signum x :% 1
35@@ -316,9 +328,11 @@
36
37 instance  (Integral a) => Fractional (Ratio a)  where
38     {-# SPECIALIZE instance Fractional Rational #-}
39-    (x:%y) / (x':%y')  =  (x*y') % (y*x')
40+    (x:%y) / (x':%y')  =  (a * b') % (b * a') where
41+        a :% a' = reduce x x'
42+        b' :% b = reduce y' y
43     recip (x:%y)       =  y % x
44-    fromRational (x:%y) =  fromInteger x :% fromInteger y
45+    fromRational (x:%y) =  fromInteger x % fromInteger y
46
47 instance  (Integral a) => Real (Ratio a)  where
48     {-# SPECIALIZE instance Real Rational #-}