4
from __future__ import absolute_import
7
from cython cimport typeof
10
def valid_underscore_literals():
12
>>> valid_underscore_literals()
14
# Copied from CPython's test_grammar.py
17
assert 1_0000_0000 == 100000000
18
assert 0b1001_0100 == 0b10010100
19
assert 0xffff_ffff == 0xffffffff
20
assert 0o5_7_7 == 0o577
21
assert 1_00_00.5 == 10000.5
24
assert 1_0 == 1_0L == 1_0LL == 1_0UL == 1_0ULL
25
assert typeof(1_0ULL) == "unsigned long long"
28
@cython.test_assert_path_exists(
29
'//IntNode[@longness = "LL"]',
30
'//IntNode[@longness = "L"]',
32
@cython.test_fail_if_path_exists('//IntNode[@longness = ""]')
35
>>> c_longs() == (1, 1, -1, 18446744073709551615) or c_longs()
39
cdef unsigned long ua = 1UL
40
cdef long long aa = 0xFFFFFFFFFFFFFFFFLL
41
cdef unsigned long long uaa = 0xFFFFFFFFFFFFFFFFULL
42
return a, ua, int(aa), uaa
44
@cython.test_assert_path_exists(
45
'//IntNode[@longness = "LL"]',
46
'//IntNode[@longness = "L"]',
48
@cython.test_fail_if_path_exists('//IntNode[@longness = ""]')
49
def negative_c_longs():
51
>>> negative_c_longs() == (-1, -9223285636854775809) or negative_c_longs()
55
cdef long long aa = -9223285636854775809LL
61
... 1, 1, 100000000000000000000000000000000, -100000000000000000000000000000000
65
return 1, 1L, 100000000000000000000000000000000, -100000000000000000000000000000000
67
@cython.test_fail_if_path_exists("//NumBinopNode", "//IntBinopNode")
68
@cython.test_assert_path_exists("//ReturnStatNode/IntNode")
69
def py_huge_calculated_long():
71
>>> py_huge_calculated_long() == (
72
... 1606938044258990275541962092341162602522202993782792835301376
73
... ) or py_huge_calculated_long()
78
@cython.test_fail_if_path_exists("//NumBinopNode", "//IntBinopNode")
79
@cython.test_assert_path_exists("//ReturnStatNode/IntNode")
80
def py_huge_computation_small_result():
82
>>> py_huge_computation_small_result()
85
return (1 << 200) >> 199
87
@cython.test_fail_if_path_exists("//NumBinopNode", "//IntBinopNode")
88
#@cython.test_assert_path_exists("//ReturnStatNode/IntNode")
89
def py_huge_computation_small_result_neg():
91
>>> py_huge_computation_small_result_neg() == (
92
... -2535301200456458802993406410752, -2535301200456458802993406410752
93
... ) or py_huge_computation_small_result_neg()
96
return -(2 ** 101), (-2) ** 101
101
>>> type(large_literal()) is int
104
return 0xFFFFFFFFFFFF
124
# different ways to write an integer in Python
136
def c_oct_py2_legacy():
138
>>> c_oct_py2_legacy()
151
return 0o01, -0o21, 0o77
153
def py_oct_py2_legacy():
155
>>> py_oct_py2_legacy()
158
return 001, -021, 077
175
return 0x01, -0x21, 0xFF
192
return 0b01, -0b10, 0b1111
196
>>> big_value() == (10**10000)
199
# Not quite a literal, but Cython expands the binop and inserts the literal
200
# into the C source. Which means it must be converted to a hex string to avoid
201
# hitting Python's integer conversion limits