Commit 5463b7e7 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

* lisp/emacs-lisp/cl-extra.el (cl-isqrt): Speed up bignum case

parent 955e3703
...@@ -332,10 +332,9 @@ If so, return the true (non-nil) value returned by PREDICATE. ...@@ -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))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment