diff --git a/numeric.c b/numeric.c index de5b02aaf9..731a809523 100644 --- a/numeric.c +++ b/numeric.c @@ -5553,7 +5553,7 @@ rb_int_digits_bigbase(VALUE num, VALUE base) } bases = rb_ary_new(); - for (VALUE b = base; int_lt(b, num) == Qtrue; b = rb_int_mul(b, b)) { + for (VALUE b = base; int_le(b, num) == Qtrue; b = rb_int_mul(b, b)) { rb_ary_push(bases, b); } digits = rb_ary_new_from_args(1, num); diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index dd6f4baa4c..c366f794b2 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -821,6 +821,9 @@ class TestBignum < Test::Unit::TestCase assert_equal([7215, 2413, 6242], T1024P.digits(10_000).first(3)) assert_equal([11], 11.digits(T1024P)) assert_equal([T1024P - 1, 1], (T1024P + T1024P - 1).digits(T1024P)) + bug21680 = '[ruby-core:123769] [Bug #21680]' + assert_equal([0] * 64 + [1], (2**512).digits(256), bug21680) + assert_equal([0] * 128 + [1], (123**128).digits(123), bug21680) end def test_digits_for_negative_numbers