summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-05 05:39:49 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-05 05:39:49 +0000
commitd22ce4a522141c2f6e847846944ddc1ec3a949f2 (patch)
tree1d1f246b6457ebed0d45ae33ba34d12e62d7facb /numeric.c
parent8797ebd662954c96a25bac1648279431a3a378a8 (diff)
* numeric.c (fix_pow): Handle special cases when base is 0, -1 or +1
[Bug #5713] [Bug #5715] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/numeric.c b/numeric.c
index 4ae5948cf0..cacccb9df6 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2951,6 +2951,13 @@ fix_pow(VALUE x, VALUE y)
if (FIXNUM_P(y)) {
long b = FIX2LONG(y);
+ if (a == 1) return INT2FIX(1);
+ if (a == -1) {
+ if (b % 2 == 0)
+ return INT2FIX(1);
+ else
+ return INT2FIX(-1);
+ }
if (b < 0)
return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y);
@@ -2960,27 +2967,18 @@ fix_pow(VALUE x, VALUE y)
if (b > 0) return INT2FIX(0);
return DBL2NUM(INFINITY);
}
- if (a == 1) return INT2FIX(1);
- if (a == -1) {
- if (b % 2 == 0)
- return INT2FIX(1);
- else
- return INT2FIX(-1);
- }
return int_pow(a, b);
}
switch (TYPE(y)) {
case T_BIGNUM:
-
- if (negative_int_p(y))
- return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y);
-
- if (a == 0) return INT2FIX(0);
if (a == 1) return INT2FIX(1);
if (a == -1) {
if (int_even_p(y)) return INT2FIX(1);
else return INT2FIX(-1);
}
+ if (negative_int_p(y))
+ return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y);
+ if (a == 0) return INT2FIX(0);
x = rb_int2big(FIX2LONG(x));
return rb_big_pow(x, y);
case T_FLOAT: