blob: 62153d190ef7619e4ed1f9aba44c321d8cff45fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# tag: cpp
cdef extern from "cpp_nonstdint.h":
ctypedef int Int24
ctypedef int Int56
ctypedef int Int88
ctypedef int Int512
cdef object one = 1
# ---
INT24_MAX = (one<<(sizeof(Int24)*8-1))-one
INT24_MIN = (-INT24_MAX-one)
def test_int24(Int24 i):
"""
>>> str(test_int24(-1))
'-1'
>>> str(test_int24(0))
'0'
>>> str(test_int24(1))
'1'
>>> test_int24(INT24_MAX) == INT24_MAX
True
>>> test_int24(INT24_MIN) == INT24_MIN
True
>>> test_int24(INT24_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int24(INT24_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int24("123") #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: ...
"""
return i
# ---
INT56_MAX = (one<<(sizeof(Int56)*8-1))-one
INT56_MIN = (-INT56_MAX-one)
def test_int56(Int56 i):
"""
>>> str(test_int56(-1))
'-1'
>>> str(test_int56(0))
'0'
>>> str(test_int56(1))
'1'
>>> test_int56(INT56_MAX) == INT56_MAX
True
>>> test_int56(INT56_MIN) == INT56_MIN
True
>>> test_int56(INT56_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int56(INT56_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int56("123") #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: ...
"""
return i
# ---
INT88_MAX = (one<<(sizeof(Int88)*8-1))-one
INT88_MIN = (-INT88_MAX-one)
def test_int88(Int88 i):
"""
>>> str(test_int88(-1))
'-1'
>>> str(test_int88(0))
'0'
>>> str(test_int88(1))
'1'
>>> test_int88(INT88_MAX) == INT88_MAX
True
>>> test_int88(INT88_MIN) == INT88_MIN
True
>>> test_int88(INT88_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int88(INT88_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int88("123") #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: ...
"""
return i
# ---
INT512_MAX = (one<<(sizeof(Int512)*8-1))-one
INT512_MIN = (-INT512_MAX-one)
def test_int512(Int512 i):
"""
>>> str(test_int512(-1))
'-1'
>>> str(test_int512(0))
'0'
>>> str(test_int512(1))
'1'
>>> test_int512(INT512_MAX) == INT512_MAX
True
>>> test_int512(INT512_MIN) == INT512_MIN
True
>>> test_int512(INT512_MIN-1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int512(INT512_MAX+1) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
OverflowError: ...
>>> test_int512("123") #doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: ...
"""
return i
# ---
|