blob: 102dac8ae7b599ec0928ddd3e68a53984e77eafc [file] [log] [blame]
Paul Sokolovsky027594e2014-01-31 17:13:51 +02001# This tests small int range for 32-bit machine
Paul Sokolovsky757ac812014-01-12 17:06:25 +02002
Paul Sokolovsky56e5ef22014-02-22 16:39:45 +02003# Small ints are variable-length encoded in MicroPython, so first
4# test that encoding works as expected.
5
6print(0)
7print(1)
8print(-1)
9# Value is split in 7-bit "subwords", and taking into account that all
10# ints in Python are signed, there're 6 bits of magnitude. So, around 2^6
11# there's "turning point"
12print(63)
13print(64)
14print(65)
15print(-63)
16print(-64)
17print(-65)
18# Maximum values of small ints on 32-bit platform
19print(1073741823)
20# Per python semantics, lexical integer is without a sign (i.e. positive)
21# and '-' is unary minus operation applied to it. That's why -1073741824
22# (min two-complement's negative value) is not allowed.
23print(-1073741823)
24
25# Operations tests
26
Paul Sokolovsky757ac812014-01-12 17:06:25 +020027a = 0x3fffff
28print(a)
29a *= 0x10
30print(a)
31a *= 0x10
32print(a)
33a += 0xff
34print(a)
35# This would overflow
36#a += 1
37
38a = -0x3fffff
39print(a)
40a *= 0x10
41print(a)
42a *= 0x10
43print(a)
44a -= 0xff
45print(a)
46# This still doesn't overflow
47a -= 1
48print(a)
49# This would overflow
50#a -= 1