Skip to content

Commit

Permalink
0.8.3.36:
Browse files Browse the repository at this point in the history
        * Fix bug reported by Paul Dietz: (GCD 0 X) returned X instead
          of (ABS X).
  • Loading branch information
Alexey Dejneka committed Sep 4, 2003
1 parent ebf2239 commit 42765fe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/code/numbers.lisp
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/arith.pure.lisp
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion version.lisp-expr
Expand Up @@ -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"

0 comments on commit 42765fe

Please sign in to comment.