src/Tools/rat.ML
changeset 24521 9565ac68c3cd
parent 23520 483fe92f00c1
child 24522 ec3e5c1a0479
--- a/src/Tools/rat.ML	Sun Sep 02 23:36:21 2007 +0200
+++ b/src/Tools/rat.ML	Mon Sep 03 08:01:35 2007 +0200
@@ -93,8 +93,10 @@
 
 fun neg (Rat (p, q)) = Rat (Integer.neg p, q);
 
-fun inv (Rat (p, 0)) = raise DIVZERO
-  | inv (Rat (p, q)) = Rat (q, p);
+fun inv (Rat (p, q)) = case Integer.sign p
+ of LESS => Rat (Integer.neg q, Integer.neg p)
+  | EQAUL => raise DIVZERO
+  | GREATER => Rat (q, p);
 
 fun rounddown (Rat (p, q)) = Rat (Integer.div p q, 1);