ruby-changes:48939
From: kazu <ko1@a...>
Date: Thu, 7 Dec 2017 00:02:37 +0900 (JST)
Subject: [ruby-changes:48939] kazu:r61058 (trunk): `Integer#pow(b)` accepts numeric
kazu 2017-12-07 00:02:31 +0900 (Thu, 07 Dec 2017) New Revision: 61058 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61058 Log: `Integer#pow(b)` accepts numeric instead of integer only and returns numeric instead of integer only same as `Integer#**` Modified files: trunk/bignum.c trunk/test/ruby/test_numeric.rb Index: bignum.c =================================================================== --- bignum.c (revision 61057) +++ bignum.c (revision 61058) @@ -7028,7 +7028,7 @@ int_pow_tmp2(VALUE x, VALUE y, long mm, https://github.com/ruby/ruby/blob/trunk/bignum.c#L7028 /* * Document-method: Integer#pow * call-seq: - * integer.pow(integer) -> integer + * integer.pow(numeric) -> numeric * integer.pow(integer, integer) -> integer * * Returns (modular) exponentiation as: Index: test/ruby/test_numeric.rb =================================================================== --- test/ruby/test_numeric.rb (revision 61057) +++ test/ruby/test_numeric.rb (revision 61058) @@ -386,6 +386,10 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L386 end def test_pow + assert_equal(2**3, 2.pow(3)) + assert_equal(2**-1, 2.pow(-1)) + assert_equal(2**0.5, 2.pow(0.5)) + assert_equal((-1)**0.5, -1.pow(0.5)) assert_equal(3**3 % 8, 3.pow(3, 8)) assert_equal(3**3 % -8, 3.pow(3,-8)) assert_equal(3**2 % -2, 3.pow(2,-2)) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/