ruby-changes:51466
From: nobu <ko1@a...>
Date: Sun, 17 Jun 2018 10:07:32 +0900 (JST)
Subject: [ruby-changes:51466] nobu:r63676 (trunk): refine Integer#**
nobu 2018-06-17 10:07:27 +0900 (Sun, 17 Jun 2018) New Revision: 63676 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63676 Log: refine Integer#** * numeric.c (fix_pow): calculate the denominator, exponent of self. Modified files: trunk/numeric.c Index: numeric.c =================================================================== --- numeric.c (revision 63675) +++ numeric.c (revision 63676) @@ -3974,8 +3974,10 @@ fix_pow(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3974 else return INT2FIX(-1); } - if (b < 0) - return num_funcall1(rb_rational_raw1(x), idPow, y); + if (b < 0) { + if (a == 0) rb_num_zerodiv(); + return rb_rational_raw(INT2FIX(1), rb_int_pow(x, LONG2NUM(-b))); + } if (b == 0) return INT2FIX(1); if (b == 1) return x; @@ -3991,8 +3993,10 @@ fix_pow(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3993 if (int_even_p(y)) return INT2FIX(1); else return INT2FIX(-1); } - if (rb_num_negative_int_p(y)) - return num_funcall1(rb_rational_raw1(x), idPow, y); + if (BIGNUM_NEGATIVE_P(y)) { + if (a == 0) rb_num_zerodiv(); + return rb_rational_raw(INT2FIX(1), rb_int_pow(x, rb_big_uminus(y))); + } if (a == 0) return INT2FIX(0); x = rb_int2big(FIX2LONG(x)); return rb_big_pow(x, y); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/