summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-13 01:04:33 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-13 01:04:33 +0000
commitc3b656bc8eb8fede8de7c2505e1135f8d7c399f0 (patch)
tree2482e65a27cd8832d2b213337ee707edf4e1b838 /bignum.c
parentc603e5c9ab09896ed269b90a637177673914a9a5 (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.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/bignum.c b/bignum.c
index fd5f385cac..a707c2d562 100644
--- a/bignum.c
+++ b/bignum.c
@@ -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;