summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/int-small.py
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-22 16:39:45 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-22 16:39:45 +0200
commit56e5ef203b01ac8dfb1cb46143f6f7c53237b79d (patch)
treea1c2267a2e6b657d29be82ac177f21e74af24707 /tests/basics/int-small.py
parentbbf0e2fe120f095ce09fcb7eb631c9fd04bd9760 (diff)
downloadmicropython-56e5ef203b01ac8dfb1cb46143f6f7c53237b79d.tar.gz
micropython-56e5ef203b01ac8dfb1cb46143f6f7c53237b79d.zip
parse: Refactor parse node encoding to support full range of small ints.
Based on suggestion by @dpgeorge at https://github.com/micropython/micropython/pull/313
Diffstat (limited to 'tests/basics/int-small.py')
-rw-r--r--tests/basics/int-small.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/basics/int-small.py b/tests/basics/int-small.py
index 53902c7e39..102dac8ae7 100644
--- a/tests/basics/int-small.py
+++ b/tests/basics/int-small.py
@@ -1,5 +1,29 @@
# This tests small int range for 32-bit machine
+# Small ints are variable-length encoded in MicroPython, so first
+# test that encoding works as expected.
+
+print(0)
+print(1)
+print(-1)
+# Value is split in 7-bit "subwords", and taking into account that all
+# ints in Python are signed, there're 6 bits of magnitude. So, around 2^6
+# there's "turning point"
+print(63)
+print(64)
+print(65)
+print(-63)
+print(-64)
+print(-65)
+# Maximum values of small ints on 32-bit platform
+print(1073741823)
+# Per python semantics, lexical integer is without a sign (i.e. positive)
+# and '-' is unary minus operation applied to it. That's why -1073741824
+# (min two-complement's negative value) is not allowed.
+print(-1073741823)
+
+# Operations tests
+
a = 0x3fffff
print(a)
a *= 0x10