Remove trailing whitespace.
[cython.git] / tests / run / int_literals.pyx
1 __doc__ = u"""
2 >>> c_longs()
3 (1, 1L, -1L, 18446744073709551615L)
4 >>> py_longs()
5 (1, 1L, 100000000000000000000000000000000L, -100000000000000000000000000000000L)
6
7 >>> py_huge_calculated_long()
8 1606938044258990275541962092341162602522202993782792835301376L
9 >>> py_huge_computation_small_result_neg()
10 (-2535301200456458802993406410752L, -2535301200456458802993406410752L)
11 """
12
13 cimport cython
14 from cython cimport typeof
15
16 import sys
17
18 if sys.version_info[0] >= 3:
19     __doc__ = __doc__.replace(u'L', u'')
20
21 import sys
22
23 if sys.version_info[0] >= 3:
24     __doc__ = __doc__.replace(u'L', u'')
25
26 def c_longs():
27     cdef long a = 1L
28     cdef unsigned long ua = 1UL
29     cdef long long aa = 0xFFFFFFFFFFFFFFFFLL
30     cdef unsigned long long uaa = 0xFFFFFFFFFFFFFFFFULL
31
32     return a, ua, aa, uaa
33
34 def py_longs():
35     return 1, 1L, 100000000000000000000000000000000, -100000000000000000000000000000000
36
37 @cython.test_fail_if_path_exists("//NumBinopNode", "//IntBinopNode")
38 @cython.test_assert_path_exists("//ReturnStatNode/IntNode")
39 def py_huge_calculated_long():
40     return 1 << 200
41
42 @cython.test_fail_if_path_exists("//NumBinopNode", "//IntBinopNode")
43 @cython.test_assert_path_exists("//ReturnStatNode/IntNode")
44 def py_huge_computation_small_result():
45     """
46     >>> py_huge_computation_small_result()
47     2
48     """
49     return (1 << 200) >> 199
50
51 @cython.test_fail_if_path_exists("//NumBinopNode", "//IntBinopNode")
52 #@cython.test_assert_path_exists("//ReturnStatNode/IntNode")
53 def py_huge_computation_small_result_neg():
54     return -(2 ** 101), (-2) ** 101
55
56 def large_literal():
57     """
58     >>> type(large_literal()) is int
59     True
60     """
61     if sys.version_info[0] >= 3 or sys.maxint > 0xFFFFFFFFFFFF:
62         return 0xFFFFFFFFFFFF
63     else:
64         return 0xFFFFFFF
65
66 def c_long_types():
67     """
68     >>> c_long_types()
69     long
70     long
71     long long
72     unsigned long
73     unsigned long
74     unsigned long long
75     """
76     print typeof(1)
77     print typeof(1L)
78     print typeof(1LL)
79     print typeof(1U)
80     print typeof(1UL)
81     print typeof(1ULL)
82
83 # different ways to write an integer in Python
84
85 def c_oct():
86     """
87     >>> c_oct()
88     (1, -17, 63)
89     """
90     cdef int a = 0o01
91     cdef int b = -0o21
92     cdef int c = 0o77
93     return a,b,c
94
95 def c_oct_py2_legacy():
96     """
97     >>> c_oct_py2_legacy()
98     (1, -17, 63)
99     """
100     cdef int a = 001
101     cdef int b = -021
102     cdef int c = 077
103     return a,b,c
104
105 def py_oct():
106     """
107     >>> py_oct()
108     (1, -17, 63)
109     """
110     return 0o01, -0o21, 0o77
111
112 def py_oct_py2_legacy():
113     """
114     >>> py_oct_py2_legacy()
115     (1, -17, 63)
116     """
117     return 001, -021, 077
118
119 def c_hex():
120     """
121     >>> c_hex()
122     (1, -33, 255)
123     """
124     cdef int a = 0x01
125     cdef int b = -0x21
126     cdef int c = 0xFF
127     return a,b,c
128
129 def py_hex():
130     """
131     >>> py_hex()
132     (1, -33, 255)
133     """
134     return 0x01, -0x21, 0xFF
135
136 def c_bin():
137     """
138     >>> c_bin()
139     (1, -2, 15)
140     """
141     cdef int a = 0b01
142     cdef int b = -0b10
143     cdef int c = 0b1111
144     return a,b,c
145
146 def py_bin():
147     """
148     >>> py_bin()
149     (1, -2, 15)
150     """
151     return 0b01, -0b10, 0b1111