diff options
| author | Stefan Monnier | 2019-06-25 17:08:01 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-06-25 17:08:01 -0400 |
| commit | 5463b7e77ab4f22bb10192fb23af6df88dde37e6 (patch) | |
| tree | ac7710dacb52acd30326b9ec68707b596a683240 | |
| parent | 955e3703736d3de5a3d0784f3b70a95132a4f7bd (diff) | |
| download | emacs-5463b7e77ab4f22bb10192fb23af6df88dde37e6.tar.gz emacs-5463b7e77ab4f22bb10192fb23af6df88dde37e6.zip | |
* lisp/emacs-lisp/cl-extra.el (cl-isqrt): Speed up bignum case
| -rw-r--r-- | lisp/emacs-lisp/cl-extra.el | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el index 90533295b68..ca33c56a958 100644 --- a/lisp/emacs-lisp/cl-extra.el +++ b/lisp/emacs-lisp/cl-extra.el | |||
| @@ -332,10 +332,9 @@ If so, return the true (non-nil) value returned by PREDICATE. | |||
| 332 | 332 | ||
| 333 | ;;;###autoload | 333 | ;;;###autoload |
| 334 | (defun cl-isqrt (x) | 334 | (defun cl-isqrt (x) |
| 335 | "Return the integer square root of the argument." | 335 | "Return the integer square root of the (integer) argument." |
| 336 | (if (and (integerp x) (> x 0)) | 336 | (if (and (integerp x) (> x 0)) |
| 337 | (let ((g (cond ((<= x 100) 10) ((<= x 10000) 100) | 337 | (let ((g (ash 2 (/ (logb x) 2))) |
| 338 | ((<= x 1000000) 1000) (t x))) | ||
| 339 | g2) | 338 | g2) |
| 340 | (while (< (setq g2 (/ (+ g (/ x g)) 2)) g) | 339 | (while (< (setq g2 (/ (+ g (/ x g)) 2)) g) |
| 341 | (setq g g2)) | 340 | (setq g g2)) |