summaryrefslogtreecommitdiff
path: root/test/ruby/test_numeric.rb
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-04 02:35:40 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-04 02:35:40 +0000
commit9b09cc8a37ca80c7126bfc4ffc39ce9dddcdb1d8 (patch)
tree077a5bcc275ca50f1588428b384e742f8366f43a /test/ruby/test_numeric.rb
parent58b3f3654634e86a3d89c74294b8356008ae8597 (diff)
bignum.c, numeric.c: add Integer#pow(b, m)
This commit is based on the pull-request #1320 created by Makoto Kishimoto. [Feature #12508] [Feature #11003] [close GH-1320] * bignum.c (rb_int_powm): Added for Integer#pow(b, m). * internal.h (rb_int_powm): Declared to refer in numeric.c. * bignum.c (bary_powm_gmp): Added for Integer#pow(b, m) using GMP. * bignum.c (int_pow_tmp1): Added for implementing Integer#pow(b, m). * bignum.c (int_pow_tmp2, int_pow_tmp3): ditto. * internal.h (rb_num_positive_int_p): Moved from numeric.c for sharing the definition with bignum.c. * internal.h (rb_num_negative_int_p, rb_num_compare_with_zero): ditto. * numeric.c(negative_int_p): Moved to internal.h for sharing the definition with bignum.c. * numeric.c (positive_int_p, compare_with_zero): ditto. * numeric.c (rb_int_odd_p): Exported (renamed from int_odd_p). * internal.h (rb_int_odd_p): ditto. * internal.h (HALF_LONG_MSB): Added. * numeric.c (SQRT_LONG_MAX): Redefined by using HALF_LONG_MSB. * test/ruby/test_numeric.rb (test_pow): Added for Integer#pow(b, m). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_numeric.rb')
-rw-r--r--test/ruby/test_numeric.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb
index 49008247ed..9b17fbb2a5 100644
--- a/test/ruby/test_numeric.rb
+++ b/test/ruby/test_numeric.rb
@@ -384,4 +384,18 @@ class TestNumeric < Test::Unit::TestCase
end
end
end
+
+ def test_pow
+ 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))
+ assert_equal((-3)**3 % 8, -3.pow(3,8))
+ assert_equal((-3)**3 % -8, -3.pow(3,-8))
+ assert_equal(5**2 % -8, 5.pow(2,-8))
+ assert_equal(4481650795473624846969600733813414725093,
+ 2120078484650058507891187874713297895455.
+ pow(5478118174010360425845660566650432540723,
+ 5263488859030795548286226023720904036518))
+ end
+
end