summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
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);