From 7b7bbd0ee7c17273fdaa3bee1ef25d72e0519a41 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 5 Apr 2018 00:59:49 +1000 Subject: [PATCH] tests/basics: Add tests for edge cases of nan-box's 47-bit small int. --- tests/basics/builtin_abs_intbig.py | 4 ++++ tests/basics/int_big1.py | 5 +++++ tests/basics/int_big_add.py | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/tests/basics/builtin_abs_intbig.py b/tests/basics/builtin_abs_intbig.py index 3dd5ea89fa..8afb7fc691 100644 --- a/tests/basics/builtin_abs_intbig.py +++ b/tests/basics/builtin_abs_intbig.py @@ -7,3 +7,7 @@ print(abs(-123456789012345678901234567890)) # edge cases for 32 and 64 bit archs (small int overflow when negating) print(abs(-0x3fffffff - 1)) print(abs(-0x3fffffffffffffff - 1)) + +# edge case for nan-boxing with 47-bit small int +i = -0x3fffffffffff +print(abs(i - 1)) diff --git a/tests/basics/int_big1.py b/tests/basics/int_big1.py index 996c45b5da..40d16c455b 100644 --- a/tests/basics/int_big1.py +++ b/tests/basics/int_big1.py @@ -90,6 +90,11 @@ x = 1073741823 # small x = -1073741823 # small x = 1073741824 # big x = -1073741824 # big +# for nan-boxing with 47-bit small ints +print(int('0x3fffffffffff', 16)) # small +print(int('-0x3fffffffffff', 16)) # small +print(int('0x400000000000', 16)) # big +print(int('-0x400000000000', 16)) # big # for 64 bit archs x = 4611686018427387903 # small x = -4611686018427387903 # small diff --git a/tests/basics/int_big_add.py b/tests/basics/int_big_add.py index f0c3336d05..b64b76ff0b 100644 --- a/tests/basics/int_big_add.py +++ b/tests/basics/int_big_add.py @@ -5,6 +5,11 @@ i = 0x3fffffff print(i + i) print(-i + -i) +# 47-bit overflow +i = 0x3fffffffffff +print(i + i) +print(-i + -i) + # 63-bit overflow i = 0x3fffffffffffffff print(i + i)