@@ -4218,10 +4218,23 @@ function factorial( n, m )
4218
4218
{
4219
4219
// recursive and memoized
4220
4220
// binomial = C(n,m) = C(n-1,m-1)+C(n-1,m) = n!/m!(n-m)!
4221
- res = Arithmetic.isDefault() ? stdMath.round(operate(function(Cnm,i){
4222
- // this is faster and will not overflow unnecesarily for default arithmetic
4223
- return Cnm*(1+n/i);
4224
- }, (n=n-m)+1, null, 2, m)) : add(factorial(sub(n, I), sub(m, I)), factorial(sub(n, I), m))/*div(factorial(n,-m), factorial(m))*/;
4221
+ if ( Arithmetic.lte(n, 10) )
4222
+ {
4223
+ res = add(factorial(sub(n, I), sub(m, I)), factorial(sub(n, I), m));/*div(factorial(n,-m), factorial(m))*/
4224
+ }
4225
+ else if ( Arithmetic.isDefault() )
4226
+ {
4227
+ res = stdMath.round(operate(function(Cnm,i){
4228
+ // this is faster and will not overflow unnecesarily for default arithmetic
4229
+ return Cnm*(1+n/i);
4230
+ }, (n=n-m)+1, null, 2, m));
4231
+ }
4232
+ else
4233
+ {
4234
+ i = add(sub(n, m), I); res = i;
4235
+ while( Arithmetic.lt(i, n) ) { i = add(i, I); res = mul(res, i); }
4236
+ res = div(res, factorial(m));
4237
+ }
4225
4238
// memoize only up to MAXMEM results
4226
4239
if ( Arithmetic.lt(n, MAXMEM) )
4227
4240
factorial.mem3[key] = res;
0 commit comments