5
@cython.test_assert_path_exists("//SingleAssignmentNode/TypecastNode")
6
@cython.test_fail_if_path_exists("//SimpleCallNode")
7
def double_to_short_int(double x):
9
>>> double_to_short_int(4.1)
11
>>> double_to_short_int(4)
13
>>> double_to_short_int('4') # doctest: +ELLIPSIS
14
Traceback (most recent call last):
20
@cython.test_assert_path_exists("//SingleAssignmentNode/TypecastNode")
21
@cython.test_fail_if_path_exists("//SimpleCallNode")
22
def double_to_pyssizet_int(double x):
24
>>> double_to_pyssizet_int(4.1)
26
>>> double_to_pyssizet_int(4)
28
>>> double_to_pyssizet_int('4') # doctest: +ELLIPSIS
29
Traceback (most recent call last):
32
cdef Py_ssize_t r = int(x)
35
@cython.test_assert_path_exists("//SingleAssignmentNode/TypecastNode")
36
@cython.test_fail_if_path_exists("//SimpleCallNode")
37
def int_to_pyssizet_int(int x):
39
>>> int_to_pyssizet_int(4.1)
41
>>> int_to_pyssizet_int(4)
43
>>> int_to_pyssizet_int('4') # doctest: +ELLIPSIS
44
Traceback (most recent call last):
47
cdef Py_ssize_t r = int(x)
50
## @cython.test_assert_path_exists("//SingleAssignmentNode/TypecastNode")
51
## @cython.test_fail_if_path_exists("//SimpleCallNode")
52
## def double_to_pyssizet_float(double x):
54
## >>> double_to_pyssizet_float(4.1)
56
## >>> double_to_pyssizet_float(4)
59
## cdef Py_ssize_t r = float(x)
62
@cython.test_assert_path_exists("//SingleAssignmentNode/TypecastNode")
63
@cython.test_fail_if_path_exists("//SimpleCallNode")
64
def int_to_short_int(int x):
66
>>> int_to_short_int(4)
68
>>> int_to_short_int('4') # doctest: +ELLIPSIS
69
Traceback (most recent call last):
70
TypeError: ...integer...
75
@cython.test_assert_path_exists("//SingleAssignmentNode/TypecastNode")
76
@cython.test_fail_if_path_exists("//SimpleCallNode")
77
def short_to_float_float(short x):
79
>>> short_to_float_float(4)
81
>>> short_to_float_float('4') # doctest: +ELLIPSIS
82
Traceback (most recent call last):
83
TypeError: ...integer...
85
cdef float r = float(x)
88
@cython.test_assert_path_exists("//SingleAssignmentNode/TypecastNode")
89
@cython.test_fail_if_path_exists("//SimpleCallNode")
90
def short_to_double_float(short x):
92
>>> short_to_double_float(4)
94
>>> short_to_double_float('4') # doctest: +ELLIPSIS
95
Traceback (most recent call last):
96
TypeError: ...integer...
98
cdef double r = float(x)
101
@cython.test_assert_path_exists("//SingleAssignmentNode/TypecastNode")
102
@cython.test_fail_if_path_exists("//SimpleCallNode")
103
def short_to_double_int(short x):
105
>>> short_to_double_int(4)
107
>>> short_to_double_int('4') # doctest: +ELLIPSIS
108
Traceback (most recent call last):
109
TypeError: ...integer...
111
cdef double r = int(x)
114
@cython.test_fail_if_path_exists("//SimpleCallNode")
115
def float_to_float_float(float x):
117
>>> 4.05 < float_to_float_float(4.1) < 4.15
119
>>> float_to_float_float(4)
121
>>> float_to_float_float('4') # doctest: +ELLIPSIS
122
Traceback (most recent call last):
125
cdef float r = float(x)
128
@cython.test_fail_if_path_exists("//SimpleCallNode",
129
"//SingleAssignmentNode//TypecastNode")
130
def double_to_double_float(double x):
132
>>> 4.05 < double_to_double_float(4.1) < 4.15
134
>>> double_to_double_float(4)
136
>>> double_to_double_float('4') # doctest: +ELLIPSIS
137
Traceback (most recent call last):
140
cdef double r = float(x)
143
# tests that cannot be optimised
145
@cython.test_fail_if_path_exists("//TypecastNode")
146
@cython.test_assert_path_exists("//PythonCapiCallNode")
147
def double_to_py_int(double x):
149
>>> double_to_py_int(4.1)
151
>>> double_to_py_int(4)
153
>>> double_to_py_int('4') # doctest: +ELLIPSIS
154
Traceback (most recent call last):
159
@cython.test_fail_if_path_exists("//SingleAssignmentNode//TypecastNode")
160
@cython.test_assert_path_exists("//PythonCapiCallNode")
161
def double_to_double_int(double x):
163
>>> double_to_double_int(4.1)
165
>>> double_to_double_int(4)
167
>>> double_to_double_int('4') # doctest: +ELLIPSIS
168
Traceback (most recent call last):
171
cdef double r = int(x)
175
@cython.test_fail_if_path_exists("//SingleAssignmentNode//TypecastNode")
176
@cython.test_assert_path_exists(
177
"//PythonCapiCallNode",
178
"//PythonCapiCallNode/PythonCapiFunctionNode/@cname = 'truncf'",
180
def float_to_float_int(float x):
182
>>> float_to_float_int(4.1)
184
>>> float_to_float_int(4)
186
>>> float_to_float_int('4') # doctest: +ELLIPSIS
187
Traceback (most recent call last):
190
cdef float r = int(x)
194
@cython.test_fail_if_path_exists("//SingleAssignmentNode//TypecastNode")
195
@cython.test_assert_path_exists(
196
"//PythonCapiCallNode",
197
"//PythonCapiCallNode/PythonCapiFunctionNode/@cname = 'truncf'",
199
def float_to_double_int(float x):
201
>>> float_to_double_int(4.1)
203
>>> float_to_double_int(4)
205
>>> float_to_double_int('4') # doctest: +ELLIPSIS
206
Traceback (most recent call last):
209
cdef double r = int(x)
213
@cython.test_fail_if_path_exists("//SingleAssignmentNode//TypecastNode")
214
@cython.test_assert_path_exists(
215
"//PythonCapiCallNode",
216
"//PythonCapiCallNode/PythonCapiFunctionNode/@cname = 'trunc'",
218
def double_to_float_int(double x):
220
>>> double_to_float_int(4.1)
222
>>> double_to_float_int(4)
224
>>> double_to_float_int('4') # doctest: +ELLIPSIS
225
Traceback (most recent call last):
228
cdef float r = int(x)
232
@cython.test_fail_if_path_exists("//SimpleCallNode")
233
@cython.test_assert_path_exists("//PythonCapiCallNode")
236
>>> 4.05 < object_float(4.1) < 4.15
238
>>> object_float(2**100) == float(2**100)
240
>>> object_float(2.5**100) == float(2.5**100)
244
>>> object_float('4')
246
>>> object_float('4.0')
248
>>> object_float('4'.encode('ascii'))
250
>>> object_float('4.0'.encode('ascii'))
255
@cython.test_fail_if_path_exists("//SimpleCallNode")
256
@cython.test_assert_path_exists("//PythonCapiCallNode")
261
>>> object_int(2**100) == 2**100 or object_int(2**100)
263
>>> object_int(-(2**100)) == -(2**100) or object_int(-(2**100))
271
>>> object_int('4'.encode('ascii'))
277
@cython.test_fail_if_path_exists("//SimpleCallNode",
278
"//CoerceFromPyTypeNode")
279
def no_args_int_cint():
281
>>> no_args_int_cint()
288
@cython.test_fail_if_path_exists("//SimpleCallNode",
289
"//CoerceFromPyTypeNode")
290
def no_args_float_cdouble():
292
>>> no_args_float_cdouble()
295
cdef double xd = float()
296
cdef float xf = float()