diff options
author | Angus Gratton <angus@redyak.com.au> | 2025-03-26 11:07:52 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-07-18 00:12:05 +1000 |
commit | 516aa02104c3344903bdda078b7c87f71f94938d (patch) | |
tree | db852578d823aab814afbf05124dfea8e0b9c464 /tests/basics/int_64_basics.py | |
parent | d07f103d68d8bb1b65cba047b9bef093b9375ebd (diff) |
py/objint_longlong: Add arithmetic overflow checks.
Long long big integer support now raises an exception on overflow rather
than returning an undefined result.
Also adds an error when shifting by a negative value.
The new arithmetic checks are added in the misc.h header.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'tests/basics/int_64_basics.py')
-rw-r--r-- | tests/basics/int_64_basics.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/basics/int_64_basics.py b/tests/basics/int_64_basics.py index 73a06b64b..289ea49b6 100644 --- a/tests/basics/int_64_basics.py +++ b/tests/basics/int_64_basics.py @@ -117,10 +117,21 @@ x = -4611686018427387904 # big # sys.maxsize is a constant bigint, so test it's compatible with dynamic ones import sys if hasattr(sys, "maxsize"): - print(sys.maxsize + 1 - 1 == sys.maxsize) + print(sys.maxsize - 1 + 1 == sys.maxsize) else: print(True) # No maxsize property in this config # test extraction of big int value via mp_obj_get_int_maybe x = 1 << 62 print('a' * (x + 4 - x)) + +# negative shifts are invalid +try: + print((1 << 48) >> -4) +except ValueError as e: + print(e) + +try: + print((1 << 48) << -6) +except ValueError as e: + print(e) |