array.c: refine descending_factorial
* array.c (descending_factorial): reduce factorial multipication. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6d5a4fefd0
commit
96223329d0
14
array.c
14
array.c
@ -5079,10 +5079,16 @@ permute0(const long n, const long r, long *const p, char *const used, const VALU
|
|||||||
static VALUE
|
static VALUE
|
||||||
descending_factorial(long from, long how_many)
|
descending_factorial(long from, long how_many)
|
||||||
{
|
{
|
||||||
VALUE cnt = LONG2FIX(how_many >= 0);
|
VALUE cnt;
|
||||||
while (how_many-- > 0) {
|
if (how_many > 0) {
|
||||||
VALUE v = LONG2FIX(from--);
|
cnt = LONG2FIX(from);
|
||||||
cnt = rb_int_mul(cnt, v);
|
while (--how_many > 0) {
|
||||||
|
long v = --from;
|
||||||
|
cnt = rb_int_mul(cnt, LONG2FIX(v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cnt = LONG2FIX(how_many == 0);
|
||||||
}
|
}
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user