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