merge revision(s) f4f728b319086eea3db6e9909fb9c849c276f813: [Backport #21680]

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

	Fix wrong condition in base multiplying loop.
This commit is contained in:
Takashi Kokubun 2025-12-08 14:44:48 -08:00
parent 625eeae0db
commit fe8221af30
3 changed files with 5 additions and 2 deletions

View File

@ -5552,7 +5552,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

@ -778,6 +778,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

View File

@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 7
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 66
#define RUBY_PATCHLEVEL 67
#include "ruby/version.h"
#include "ruby/internal/abi.h"