bignum.c: refine pow

* bignum.c (rb_big_pow): make Complex and Rational instances from
  calculated results by API functions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-06-13 01:04:33 +00:00
parent c603e5c9ab
commit c3b656bc8e

View File

@ -6209,8 +6209,10 @@ rb_big_pow(VALUE x, VALUE y)
if (y == INT2FIX(0)) return INT2FIX(1);
if (RB_FLOAT_TYPE_P(y)) {
d = RFLOAT_VALUE(y);
if ((BIGNUM_NEGATIVE_P(x) && !BIGZEROP(x)) && d != round(d))
return rb_funcall(rb_complex_raw1(x), idPow, 1, y);
if ((BIGNUM_NEGATIVE_P(x) && !BIGZEROP(x)) && d != round(d)) {
x = DBL2NUM(pow(-rb_big2dbl(x), d));
return rb_complex_polar(x, DBL2NUM(d * M_PI));
}
}
else if (RB_BIGNUM_TYPE_P(y)) {
y = bignorm(y);
@ -6223,7 +6225,7 @@ rb_big_pow(VALUE x, VALUE y)
yy = FIX2LONG(y);
if (yy < 0)
return rb_funcall(rb_rational_raw1(x), idPow, 1, y);
return rb_rational_raw(INT2FIX(1), rb_big_pow(x, INT2NUM(-yy)));
else {
VALUE z = 0;
SIGNED_VALUE mask;