circuitpython/tests/basics/int-mpz.py
Damien George 06201ff3d6 py: Implement bit-shift and not operations for mpz.
Implement not, shl and shr in mpz library.  Add function to create mpzs
on the stack, used for memory efficiency when rhs is a small int.
Factor out code to parse base-prefix of number into a dedicated function.
2014-03-01 19:50:50 +00:00

58 lines
1.1 KiB
Python

# to test arbitrariy precision integers
x = 1000000000000000000000000000000
y = 2000000000000000000000000000000
# printing
print(x)
print(y)
# addition
print(x + 1)
print(x + y)
# subtraction
print(x - 1)
print(x - y)
print(y - x)
# multiplication
print(x * 2)
print(x * y)
# integer division
print(x // 2)
print(y // x)
# bit inversion
print(~x)
print(~(-x))
# left shift
x = 0x10000000000000000000000
for i in range(32):
x = x << 1
print(x)
# right shift
x = 0x10000000000000000000000
for i in range(32):
x = x >> 1
print(x)
# left shift of a negative number
for i in range(8):
print(-10000000000000000000000000 << i)
print(-10000000000000000000000001 << i)
print(-10000000000000000000000002 << i)
print(-10000000000000000000000003 << i)
print(-10000000000000000000000004 << i)
# right shift of a negative number
for i in range(8):
print(-10000000000000000000000000 >> i)
print(-10000000000000000000000001 >> i)
print(-10000000000000000000000002 >> i)
print(-10000000000000000000000003 >> i)
print(-10000000000000000000000004 >> i)