mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-23 22:20:24 -08:00
* lisp/emacs-lisp/cl-extra.el (cl-isqrt): Speed up bignum case
This commit is contained in:
parent
955e370373
commit
5463b7e77a
1 changed files with 2 additions and 3 deletions
|
|
@ -332,10 +332,9 @@ If so, return the true (non-nil) value returned by PREDICATE.
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun cl-isqrt (x)
|
(defun cl-isqrt (x)
|
||||||
"Return the integer square root of the argument."
|
"Return the integer square root of the (integer) argument."
|
||||||
(if (and (integerp x) (> x 0))
|
(if (and (integerp x) (> x 0))
|
||||||
(let ((g (cond ((<= x 100) 10) ((<= x 10000) 100)
|
(let ((g (ash 2 (/ (logb x) 2)))
|
||||||
((<= x 1000000) 1000) (t x)))
|
|
||||||
g2)
|
g2)
|
||||||
(while (< (setq g2 (/ (+ g (/ x g)) 2)) g)
|
(while (< (setq g2 (/ (+ g (/ x g)) 2)) g)
|
||||||
(setq g g2))
|
(setq g g2))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue