changeset 107791:439c9c198a6b

(calcFunc-fdiv): Allow `fdiv' to divide fractions.
author Jay Belanger <jay.p.belanger@gmail.com>
date Tue, 06 Apr 2010 20:33:00 -0500
parents f56b90a69fac
children 84df551e8c64
files lisp/calc/calc-frac.el
diffstat 1 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/calc/calc-frac.el	Tue Apr 06 14:17:55 2010 -0400
+++ b/lisp/calc/calc-frac.el	Tue Apr 06 20:33:00 2010 -0500
@@ -205,16 +205,32 @@
 	    n temp))
     (math-div n d)))
 
-
-
 (defun calcFunc-fdiv (a b)   ; [R I I] [Public]
-  (if (Math-num-integerp a)
-      (if (Math-num-integerp b)
-	  (if (Math-zerop b)
-	      (math-reject-arg a "*Division by zero")
-	    (math-make-frac (math-trunc a) (math-trunc b)))
-	(math-reject-arg b 'integerp))
-    (math-reject-arg a 'integerp)))
+  (cond
+   ((Math-num-integerp a)
+    (cond 
+     ((Math-num-integerp b)
+      (if (Math-zerop b)
+	  (math-reject-arg a "*Division by zero")
+	(math-make-frac (math-trunc a) (math-trunc b))))
+     ((eq (car-safe b) 'frac)
+      (if (Math-zerop (cadr b))
+	  (math-reject-arg a "*Division by zero")
+	(math-make-frac (math-mul (math-trunc a) (caddr b)) (cadr b))))
+     (t (math-reject-arg b 'integerp))))
+   ((eq (car-safe a) 'frac)
+    (cond 
+     ((Math-num-integerp b)
+      (if (Math-zerop b)
+	  (math-reject-arg a "*Division by zero")
+	(math-make-frac (cadr a) (math-mul (caddr a) (math-trunc b)))))
+     ((eq (car-safe b) 'frac)
+      (if (Math-zerop (cadr b))
+	  (math-reject-arg a "*Division by zero")
+	(math-make-frac (math-mul (cadr a) (caddr b)) (math-mul (caddr a) (cadr b)))))
+     (t (math-reject-arg b 'integerp))))
+   (t 
+    (math-reject-arg a 'integerp))))
 
 (provide 'calc-frac)