Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions graalpython/com.oracle.graal.python.test/src/tests/test_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,20 @@ def test_int_from_unicode_whitespace():
assert int("123\xa0") == 123


def test_str_with_max_str_digits():
previous = sys.get_int_max_str_digits()
try:
sys.set_int_max_str_digits(4300)
# 2**14284 has 4300 digits and the same bit length as 10**4300
for value in (2 ** 14284, 10 ** 4300 - 1, -(10 ** 4300 - 1)):
assert len(str(abs(value))) == 4300
assert int(str(value)) == value
assert repr(value) == str(value)
assert_raises(ValueError, str, 10 ** 4300)
assert_raises(ValueError, str, -(10 ** 4300))
finally:
sys.set_int_max_str_digits(previous)


def test_create_int_from_float():
assert int(123.0) == 123
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2659,11 +2659,12 @@ static TruffleString doPInt(PInt self,
* length, which is the number of 30 bit chunks, in a special formula.
*
* Our check compares the bit length reported by BigInteger against a precomputed bit
* length of a smallest positive number that is over the limit.
* length of a smallest positive number that is over the limit. Numbers of exactly that
* bit length can still be within the limit, so they are left to the post check.
*/
if (intMaxStrDigits > 0) {
int bitLength = positiveBitLength(self);
if (bitLength >= maxDigitsBitLengthProfile.profile(inliningTarget, context.getMinIntBitLengthOverLimit())) {
if (bitLength > maxDigitsBitLengthProfile.profile(inliningTarget, context.getMinIntBitLengthOverLimit())) {
throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.EXCEEDS_THE_LIMIT_FOR_INTEGER_STRING_CONVERSION, intMaxStrDigits);
}
}
Expand Down