[Bug #21680] Fix (base**power_of_two).digits(base) bug (#15144)

Fix wrong condition in base multiplying loop.
This commit is contained in:
tomoya ishida 2025-11-12 13:58:38 +09:00 committed by GitHub
parent c5937c1bca
commit f4f728b319
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2025-11-12 04:59:06 +00:00
Merged-By: tompng <tomoyapenguin@gmail.com>
2 changed files with 4 additions and 1 deletions

View File

@ -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);

View File

@ -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