0.8.3.36:
authorAlexey Dejneka <adejneka@comail.ru>
Thu, 4 Sep 2003 16:09:11 +0000 (16:09 +0000)
committerAlexey Dejneka <adejneka@comail.ru>
Thu, 4 Sep 2003 16:09:11 +0000 (16:09 +0000)
        * Fix bug reported by Paul Dietz: (GCD 0 X) returned X instead
          of (ABS X).

NEWS
src/code/numbers.lisp
tests/arith.pure.lisp
version.lisp-expr

diff --git a/NEWS b/NEWS
index e3cc1b3..faea919 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2038,6 +2038,7 @@ changes in sbcl-0.8.4 relative to sbcl-0.8.3:
        circumstances.
     ** optimizer for (EXPT X 0) did not work for X not of type FLOAT.
     ** (GCD 0 <negative-integer>) returned <negative-integer>.
+    ** LCM should return a non-negative integer.
 
 planned incompatible changes in 0.8.x:
   * (not done yet, but planned:) When the profiling interface settles
index 1c27cd1..c2a1a6b 100644 (file)
 
 (defun two-arg-lcm (n m)
   (declare (integer n m))
-  (* (truncate (max n m) (gcd n m)) (min n m)))
+  (let ((m (abs m))
+        (n (abs n)))
+    (multiple-value-bind (max min)
+        (if (> m n)
+            (values m n)
+            (values n m))
+      (* (truncate max (gcd n m)) min))))
 
 ;;; Do the GCD of two integer arguments. With fixnum arguments, we use the
 ;;; binary GCD algorithm from Knuth's seminumerical algorithms (slightly
index 3fc39fc..de583e5 100644 (file)
                   (= (funcall fn 3) x3))
        (error "bad results for ~D" x)))))
 
+;;; Bugs reported by Paul Dietz:
+
 ;;; (GCD 0 x) must return (abs x)
 (dolist (x (list -10 (* 3 most-negative-fixnum)))
   (assert (= (gcd 0 x) (abs x))))
+;;; LCM returns a non-negative number
+(assert (= (lcm 4 -10) 20))
index b7b69a0..73b53e1 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"0.8.3.35"
+"0.8.3.36"