mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
refine Integer#**
* numeric.c (fix_pow): calculate the denominator, exponent of self. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
47bd700774
commit
f12cc0e6f7
1 changed files with 8 additions and 4 deletions
12
numeric.c
12
numeric.c
|
@ -3974,8 +3974,10 @@ fix_pow(VALUE x, VALUE y)
|
|||
else
|
||||
return INT2FIX(-1);
|
||||
}
|
||||
if (b < 0)
|
||||
return num_funcall1(rb_rational_raw1(x), idPow, y);
|
||||
if (b < 0) {
|
||||
if (a == 0) rb_num_zerodiv();
|
||||
return rb_rational_raw(INT2FIX(1), rb_int_pow(x, LONG2NUM(-b)));
|
||||
}
|
||||
|
||||
if (b == 0) return INT2FIX(1);
|
||||
if (b == 1) return x;
|
||||
|
@ -3991,8 +3993,10 @@ fix_pow(VALUE x, VALUE y)
|
|||
if (int_even_p(y)) return INT2FIX(1);
|
||||
else return INT2FIX(-1);
|
||||
}
|
||||
if (rb_num_negative_int_p(y))
|
||||
return num_funcall1(rb_rational_raw1(x), idPow, y);
|
||||
if (BIGNUM_NEGATIVE_P(y)) {
|
||||
if (a == 0) rb_num_zerodiv();
|
||||
return rb_rational_raw(INT2FIX(1), rb_int_pow(x, rb_big_uminus(y)));
|
||||
}
|
||||
if (a == 0) return INT2FIX(0);
|
||||
x = rb_int2big(FIX2LONG(x));
|
||||
return rb_big_pow(x, y);
|
||||
|
|
Loading…
Add table
Reference in a new issue