int_big_to_small: Bifurcate test using small_int_max.

Different results are needed for different integer sizes.

Signed-off-by: Jeff Epler <jepler@gmail.com>
This commit is contained in:
Jeff Epler 2025-07-15 18:28:35 +01:00
parent bceec06655
commit 3e9d7cdb32
3 changed files with 67 additions and 0 deletions

View file

@ -5,6 +5,16 @@ except:
print("SKIP")
raise SystemExit
micropython.heap_lock()
try:
k = (1 << 29)
k = k + 20
except MemoryError:
micropython.heap_unlock()
print("SKIP")
raise SystemExit
micropython.heap_unlock()
# All less than small int max.
for d in (0, 27, 1<<29, -1861, -(1<<29)):
i = 1<<70

View file

@ -0,0 +1,32 @@
try:
import micropython
micropython.heap_lock
except:
print("SKIP")
raise SystemExit
micropython.heap_lock()
try:
k = (1 << 28)
k = k + 20
except MemoryError:
micropython.heap_unlock()
print("SKIP")
raise SystemExit
micropython.heap_unlock()
# All less than small int max.
for d in (0, 27, 1<<28, -1861, -(1<<28)):
i = 1<<70
print(i)
j = (1<<70) + d
print(j)
# k should now be a small int.
k = j - i
print(k)
# Now verify that working with k doesn't allocate (i.e. it's a small int).
micropython.heap_lock()
print(k + 20)
print(k // 20)
micropython.heap_unlock()

View file

@ -0,0 +1,25 @@
1180591620717411303424
1180591620717411303424
0
20
0
1180591620717411303424
1180591620717411303451
27
47
1
1180591620717411303424
1180591620717679738880
268435456
268435476
13421772
1180591620717411303424
1180591620717411301563
-1861
-1841
-94
1180591620717411303424
1180591620717142867968
-268435456
-268435436
-13421773