diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-17 01:07:27 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-17 01:07:27 +0000 |
commit | f12cc0e6f798475e70860d8532d59d3fbc6af218 (patch) | |
tree | 0d985313ee92bfbd48a7a87b3db44a65cdf44b2c | |
parent | 47bd700774500bdc69f6fe88ff630785b59f8108 (diff) |
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
-rw-r--r-- | numeric.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -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); |