1# to test arbitrariy precision integers
2
3x = 1000000000000000000000000000000
4xn = -1000000000000000000000000000000
5y = 2000000000000000000000000000000
6
7# printing
8print(x)
9print(y)
10print('%#X' % (x - x)) # print prefix
11print('{:#,}'.format(x)) # print with commas
12
13# addition
14print(x + 1)
15print(x + y)
16print(x + xn == 0)
17print(bool(x + xn))
18
19# subtraction
20print(x - 1)
21print(x - y)
22print(y - x)
23print(x - x == 0)
24print(bool(x - x))
25
26# multiplication
27print(x * 2)
28print(x * y)
29
30# integer division
31print(x // 2)
32print(y // x)
33
34# bit inversion
35print(~x)
36print(~(-x))
37
38# left shift
39x = 0x10000000000000000000000
40for i in range(32):
41    x = x << 1
42    print(x)
43
44# right shift
45x = 0x10000000000000000000000
46for i in range(32):
47    x = x >> 1
48    print(x)
49
50# left shift of a negative number
51for i in range(8):
52    print(-10000000000000000000000000 << i)
53    print(-10000000000000000000000001 << i)
54    print(-10000000000000000000000002 << i)
55    print(-10000000000000000000000003 << i)
56    print(-10000000000000000000000004 << i)
57
58# right shift of a negative number
59for i in range(8):
60    print(-10000000000000000000000000 >> i)
61    print(-10000000000000000000000001 >> i)
62    print(-10000000000000000000000002 >> i)
63    print(-10000000000000000000000003 >> i)
64    print(-10000000000000000000000004 >> i)
65
66# conversion from string
67print(int("123456789012345678901234567890"))
68print(int("-123456789012345678901234567890"))
69print(int("123456789012345678901234567890abcdef", 16))
70print(int("123456789012345678901234567890ABCDEF", 16))
71print(int("1234567890abcdefghijklmnopqrstuvwxyz", 36))
72
73# invalid characters in string
74try:
75    print(int("123456789012345678901234567890abcdef"))
76except ValueError:
77    print('ValueError');
78try:
79    print(int("123456789012345678901234567890\x01"))
80except ValueError:
81    print('ValueError');
82
83# test constant integer with more than 255 chars
84x = 0x84ce72aa8699df436059f052ac51b6398d2511e49631bcb7e71f89c499b9ee425dfbc13a5f6d408471b054f2655617cbbaf7937b7c80cd8865cf02c8487d30d2b0fbd8b2c4e102e16d828374bbc47b93852f212d5043c3ea720f086178ff798cc4f63f787b9c2e419efa033e7644ea7936f54462dc21a6c4580725f7f0e7d1aaaaaaa
85print(x)
86
87# test parsing ints just on threshold of small to big
88# for 32 bit archs
89x = 1073741823 # small
90x = -1073741823 # small
91x = 1073741824 # big
92x = -1073741824 # big
93# for nan-boxing with 47-bit small ints
94print(int('0x3fffffffffff', 16)) # small
95print(int('-0x3fffffffffff', 16)) # small
96print(int('0x400000000000', 16)) # big
97print(int('-0x400000000000', 16)) # big
98# for 64 bit archs
99x = 4611686018427387903 # small
100x = -4611686018427387903 # small
101x = 4611686018427387904 # big
102x = -4611686018427387904 # big
103
104# sys.maxsize is a constant mpz, so test it's compatible with dynamic ones
105try:
106    import usys as sys
107except ImportError:
108    import sys
109print(sys.maxsize + 1 - 1 == sys.maxsize)
110
111# test extraction of big int value via mp_obj_get_int_maybe
112x = 1 << 70
113print('a' * (x + 4 - x))
114