diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-13 01:04:33 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-13 01:04:33 +0000 |
commit | c3b656bc8eb8fede8de7c2505e1135f8d7c399f0 (patch) | |
tree | 2482e65a27cd8832d2b213337ee707edf4e1b838 /bignum.c | |
parent | c603e5c9ab09896ed269b90a637177673914a9a5 (diff) |
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
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -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; |