From 42765fe1c5c3ae34ad199ffdead00c2fc4e8cddb Mon Sep 17 00:00:00 2001 From: Alexey Dejneka Date: Thu, 4 Sep 2003 16:09:11 +0000 Subject: [PATCH] 0.8.3.36: * Fix bug reported by Paul Dietz: (GCD 0 X) returned X instead of (ABS X). --- NEWS | 1 + src/code/numbers.lisp | 8 +++++++- tests/arith.pure.lisp | 4 ++++ version.lisp-expr | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index e3cc1b3..faea919 100644 --- 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 ) returned . + ** LCM should return a non-negative integer. planned incompatible changes in 0.8.x: * (not done yet, but planned:) When the profiling interface settles diff --git a/src/code/numbers.lisp b/src/code/numbers.lisp index 1c27cd1..c2a1a6b 100644 --- a/src/code/numbers.lisp +++ b/src/code/numbers.lisp @@ -1263,7 +1263,13 @@ (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 diff --git a/tests/arith.pure.lisp b/tests/arith.pure.lisp index 3fc39fc..de583e5 100644 --- a/tests/arith.pure.lisp +++ b/tests/arith.pure.lisp @@ -103,6 +103,10 @@ (= (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)) diff --git a/version.lisp-expr b/version.lisp-expr index b7b69a0..73b53e1 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -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" -- 1.7.10.4