]> git.eshelyaron.com Git - emacs.git/commit
Calc: fix binomial coefficients for negative arguments (bug#16999)
authorMattias Engdegård <mattiase@acm.org>
Fri, 11 Sep 2020 09:43:15 +0000 (11:43 +0200)
committerMattias Engdegård <mattiase@acm.org>
Mon, 14 Sep 2020 09:19:22 +0000 (11:19 +0200)
commit0e00f199cd3599977f75326bb7adc9d70390661e
tree8d3faf34a7beaff4f09f465e8d9a357a6943068a
parentf66829e0f47a54a51fd1378acbf2b1085673790f
Calc: fix binomial coefficients for negative arguments (bug#16999)

For some values outside integers 0≤k≤n, (n choose k) gave wrong
results, entered infinite recursion or used unreasonably amounts of
stack space.  This change fixes that and extends the function to all
integer arguments using the definitions from M. J. Kronenburg
(https://arxiv.org/abs/1105.3689).

* lisp/calc/calc-comb.el (calcFunc-choose):
Fix sign error to prevent infinite recursion and extend function to
handle all integer arguments.
(math-choose-iter, math-choose-float-iter): Rewrite in iterative form;
no TCO in elisp yet.
* test/lisp/calc/calc-tests.el (calc-tests--fac, calc-tests--choose)
(calc-tests--check-choose, calc-tests--explain-choose)
(calc-tests--calc-to-number): New helper functions.
(calc-choose): New test.
lisp/calc/calc-comb.el
test/lisp/calc/calc-tests.el