diff options
| author | Paul Eggert | 2015-06-27 12:16:51 -0700 |
|---|---|---|
| committer | Paul Eggert | 2015-06-27 12:19:22 -0700 |
| commit | da5e0050ac161bd9d665c4b406a95bee4f3b4085 (patch) | |
| tree | 1f3d6da0846404b7dabce698abb236cc1870e13d | |
| parent | efc262f5f8a16d25c0db4e80fa52e693897fa41f (diff) | |
| download | emacs-da5e0050ac161bd9d665c4b406a95bee4f3b4085.tar.gz emacs-da5e0050ac161bd9d665c4b406a95bee4f3b4085.zip | |
cl-extra fixes for most-negative-fixnum
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-random):
Don't mishandle an argument equal to most-negative-fixnum,
whose absolute value equals itself.
(cl-gcd, cl-lcm): Use dolist rather than doing it by hand.
| -rw-r--r-- | lisp/emacs-lisp/cl-extra.el | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el index 0a6bc3afda7..3313cc77db5 100644 --- a/lisp/emacs-lisp/cl-extra.el +++ b/lisp/emacs-lisp/cl-extra.el | |||
| @@ -299,22 +299,21 @@ If so, return the true (non-nil) value returned by PREDICATE. | |||
| 299 | ;;;###autoload | 299 | ;;;###autoload |
| 300 | (defun cl-gcd (&rest args) | 300 | (defun cl-gcd (&rest args) |
| 301 | "Return the greatest common divisor of the arguments." | 301 | "Return the greatest common divisor of the arguments." |
| 302 | (let ((a (abs (or (pop args) 0)))) | 302 | (let ((a (or (pop args) 0))) |
| 303 | (while args | 303 | (dolist (b args) |
| 304 | (let ((b (abs (pop args)))) | 304 | (while (/= b 0) |
| 305 | (while (> b 0) (setq b (% a (setq a b)))))) | 305 | (setq b (% a (setq a b))))) |
| 306 | a)) | 306 | (abs a))) |
| 307 | 307 | ||
| 308 | ;;;###autoload | 308 | ;;;###autoload |
| 309 | (defun cl-lcm (&rest args) | 309 | (defun cl-lcm (&rest args) |
| 310 | "Return the least common multiple of the arguments." | 310 | "Return the least common multiple of the arguments." |
| 311 | (if (memq 0 args) | 311 | (if (memq 0 args) |
| 312 | 0 | 312 | 0 |
| 313 | (let ((a (abs (or (pop args) 1)))) | 313 | (let ((a (or (pop args) 1))) |
| 314 | (while args | 314 | (dolist (b args) |
| 315 | (let ((b (abs (pop args)))) | 315 | (setq a (* (/ a (cl-gcd a b)) b))) |
| 316 | (setq a (* (/ a (cl-gcd a b)) b)))) | 316 | (abs a)))) |
| 317 | a))) | ||
| 318 | 317 | ||
| 319 | ;;;###autoload | 318 | ;;;###autoload |
| 320 | (defun cl-isqrt (x) | 319 | (defun cl-isqrt (x) |
| @@ -431,7 +430,7 @@ Optional second arg STATE is a random-state object." | |||
| 431 | ;; Inspired by "ran3" from Numerical Recipes. Additive congruential method. | 430 | ;; Inspired by "ran3" from Numerical Recipes. Additive congruential method. |
| 432 | (let ((vec (aref state 3))) | 431 | (let ((vec (aref state 3))) |
| 433 | (if (integerp vec) | 432 | (if (integerp vec) |
| 434 | (let ((i 0) (j (- 1357335 (% (abs vec) 1357333))) (k 1)) | 433 | (let ((i 0) (j (- 1357335 (abs (% vec 1357333)))) (k 1)) |
| 435 | (aset state 3 (setq vec (make-vector 55 nil))) | 434 | (aset state 3 (setq vec (make-vector 55 nil))) |
| 436 | (aset vec 0 j) | 435 | (aset vec 0 j) |
| 437 | (while (> (setq i (% (+ i 21) 55)) 0) | 436 | (while (> (setq i (% (+ i 21) 55)) 0) |