From f92924923dd4d707abc8bf431d3c3e746fd8515a Mon Sep 17 00:00:00 2001 From: mrkn Date: Sat, 30 Dec 2017 14:50:15 +0000 Subject: [PATCH] numeric.c: Fix Integer#pow with a large Fixnum modulo * numeric.c: Fix Integer#pow with a large Fixnum modulo [Bug #14259] [ruby-core:84562] * test/ruby/test_numeric.rb: add assertions for reproducing this bug. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bignum.c | 4 +++- test/ruby/test_numeric.rb | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bignum.c b/bignum.c index 148276743f..7ffb798e5e 100644 --- a/bignum.c +++ b/bignum.c @@ -7016,7 +7016,9 @@ int_pow_tmp2(VALUE x, VALUE y, long mm, int nega_flg) xx = MUL_MODULO(xx, xx, m); } -#ifndef DLONG +#ifdef DLONG + tmp = tmp2; +#else tmp = FIX2LONG(tmp2); #endif if (nega_flg && tmp) { diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb index 02a6b8f4a8..6efc40320a 100644 --- a/test/ruby/test_numeric.rb +++ b/test/ruby/test_numeric.rb @@ -400,6 +400,11 @@ class TestNumeric < Test::Unit::TestCase 2120078484650058507891187874713297895455. pow(5478118174010360425845660566650432540723, 5263488859030795548286226023720904036518)) + + assert_equal(12, 12.pow(1, 10000000000), '[Bug #14259]') + assert_equal(12, 12.pow(1, 10000000001), '[Bug #14259]') + assert_equal(12, 12.pow(1, 10000000002), '[Bug #14259]') + assert_equal(17298641040, 12.pow(72387894339363242, 243682743764), '[Bug #14259]') end end