ruby-changes:51436
From: nobu <ko1@a...>
Date: Wed, 13 Jun 2018 10:04:45 +0900 (JST)
Subject: [ruby-changes:51436] nobu:r63642 (trunk): bignum.c: refine pow
nobu 2018-06-13 10:04:33 +0900 (Wed, 13 Jun 2018) New Revision: 63642 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63642 Log: bignum.c: refine pow * bignum.c (rb_big_pow): make Complex and Rational instances from calculated results by API functions. Modified files: trunk/bignum.c Index: bignum.c =================================================================== --- bignum.c (revision 63641) +++ bignum.c (revision 63642) @@ -6209,8 +6209,10 @@ rb_big_pow(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6209 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) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6225 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/