mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-25 10:47:00 +00:00
Use iteration in math-factorial-iter
* lisp/calc/calc-comb.el (math-factorial-iter): Use iteration instead of recursion to avoid max-specpdl-size problem. Copyright-paperwork-exempt: yes
This commit is contained in:
parent
0c98dec5c9
commit
d831312d66
@ -362,11 +362,13 @@
|
||||
(math-gammap1-raw '(float -25 -2))))
|
||||
|
||||
(defun math-factorial-iter (count n f)
|
||||
(if (= (% n 5) 1)
|
||||
(math-working (format "factorial(%d)" (1- n)) f))
|
||||
(if (> count 0)
|
||||
(math-factorial-iter (1- count) (1+ n) (math-mul n f))
|
||||
f))
|
||||
(while (> count 0)
|
||||
(if (= (% n 5) 1)
|
||||
(math-working (format "factorial(%d)" (1- n)) f))
|
||||
(setq count (1- count)
|
||||
f (math-mul n f)
|
||||
n (1+ n)))
|
||||
f)
|
||||
|
||||
(defun calcFunc-dfact (n) ; [I I] [F F] [Public]
|
||||
(cond ((Math-integer-negp n)
|
||||
|
Loading…
Reference in New Issue
Block a user