aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-17 01:07:27 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-17 01:07:27 +0000
commitf12cc0e6f798475e70860d8532d59d3fbc6af218 (patch)
tree0d985313ee92bfbd48a7a87b3db44a65cdf44b2c /numeric.c
parent47bd700774500bdc69f6fe88ff630785b59f8108 (diff)
downloadruby-f12cc0e6f798475e70860d8532d59d3fbc6af218.tar.gz
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
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/numeric.c b/numeric.c
index 7047f9185d..30afc581fe 100644
--- a/numeric.c
+++ b/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);