3
# distutils: extra_compile_args=-fwrapv
11
max_long_long = (<object>2) ** (sizeof(long long) * 8 - 1) - 1
18
>>> _abs = abs_as_name()
34
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
35
"//ReturnStatNode//NameNode[@entry.cname = 'abs']")
43
return -abs(a), 100 - abs(a)
45
@cython.overflowcheck(True)
46
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
47
"//ReturnStatNode//NameNode[@entry.cname = 'abs']")
52
>>> int_abs(-5.1) == 5
54
>>> int_abs(-max_int-1) #doctest: +ELLIPSIS
55
Traceback (most recent call last):
58
>>> int_abs(max_int) == abs(max_int) or (max_int, int_abs(max_int), abs(max_int))
63
@cython.overflowcheck(True)
64
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
65
"//ReturnStatNode//NameNode[@entry.cname = 'abs']")
66
cdef int c_int_abs(int a) except * nogil:
69
def test_c_int_abs(int a):
71
>>> test_c_int_abs(-5) == 5
73
>>> test_c_int_abs(-5.1) == 5
75
>>> test_c_int_abs(-max_int-1) #doctest: +ELLIPSIS
76
Traceback (most recent call last):
79
>>> test_c_int_abs(max_int) == abs(max_int) or (max_int, test_c_int_abs(max_int), abs(max_int))
84
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']")
85
@cython.test_fail_if_path_exists("//ReturnStatNode//NameNode[@entry.cname = 'abs']",
86
"//ReturnStatNode//NameNode[@entry.cname = 'labs']")
87
def uint_abs(unsigned int a):
89
>>> uint_abs(max_int) == abs(max_int) or (max_int, uint_abs(max_int), abs(max_int))
94
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']")
95
@cython.test_fail_if_path_exists("//ReturnStatNode//NameNode[@entry.cname = 'abs']",
96
"//ReturnStatNode//NameNode[@entry.cname = 'labs']")
97
cdef unsigned int c_uint_abs(unsigned int a) nogil:
100
def test_c_uint_abs(unsigned int a):
102
>>> test_c_uint_abs(max_int) == abs(max_int) or (max_int, test_c_uint_abs(max_int), abs(max_int))
107
@cython.overflowcheck(True)
108
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
109
"//ReturnStatNode//NameNode[@entry.cname = 'labs']")
112
>>> long_abs(-5) == 5
114
>>> long_abs(-5.1) == 5
116
>>> long_abs(-max_long-1) #doctest: +ELLIPSIS
117
Traceback (most recent call last):
120
>>> long_abs(max_long) == abs(max_long) or (max_long, long_abs(max_long), abs(max_long))
125
@cython.overflowcheck(True)
126
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
127
"//ReturnStatNode//NameNode[@entry.cname = 'labs']")
128
cdef long c_long_abs(long a) except * nogil:
131
def test_c_long_abs(long a):
133
>>> test_c_long_abs(-5) == 5
135
>>> test_c_long_abs(-5.1) == 5
137
>>> test_c_long_abs(-max_long-1) #doctest: +ELLIPSIS
138
Traceback (most recent call last):
141
>>> test_c_long_abs(max_long) == abs(max_long) or (max_long, test_c_long_abs(max_long), abs(max_long))
146
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']")
147
@cython.test_fail_if_path_exists("//ReturnStatNode//NameNode[@entry.cname = 'abs']",
148
"//ReturnStatNode//NameNode[@entry.cname = 'labs']")
149
def ulong_abs(unsigned long a):
151
>>> ulong_abs(max_long) == abs(max_long) or (max_int, ulong_abs(max_long), abs(max_long))
153
>>> ulong_abs(max_long + 5) == abs(max_long + 5) or (max_long + 5, ulong_abs(max_long + 5), abs(max_long + 5))
158
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']")
159
@cython.test_fail_if_path_exists("//ReturnStatNode//NameNode[@entry.cname = 'abs']",
160
"//ReturnStatNode//NameNode[@entry.cname = 'labs']")
161
cdef unsigned long c_ulong_abs(unsigned long a) nogil:
164
def test_c_ulong_abs(unsigned long a):
166
>>> test_c_ulong_abs(max_long) == abs(max_long) or (max_int, test_c_ulong_abs(max_long), abs(max_long))
168
>>> test_c_ulong_abs(max_long + 5) == abs(max_long + 5) or (max_long + 5, test_c_ulong_abs(max_long + 5), abs(max_long + 5))
171
return c_ulong_abs(a)
173
@cython.overflowcheck(True)
174
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
175
"//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_longlong']")
176
def long_long_abs(long long a):
178
>>> long_long_abs(-(2**33)) == 2**33
180
>>> long_long_abs(-max_long_long-1) #doctest: +ELLIPSIS
181
Traceback (most recent call last):
184
>>> long_long_abs(max_long_long) == abs(max_long_long) or (max_long_long, long_long_abs(max_long_long), abs(max_long_long))
189
@cython.overflowcheck(True)
190
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
191
"//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_longlong']")
192
cdef long long c_long_long_abs(long long a) except * nogil:
195
def test_c_long_long_abs(long long a):
197
>>> test_c_long_long_abs(-(2**33)) == 2**33
199
>>> test_c_long_long_abs(-max_long_long-1) #doctest: +ELLIPSIS
200
Traceback (most recent call last):
203
>>> test_c_long_long_abs(max_long_long) == abs(max_long_long) or (max_long_long, test_c_long_long_abs(max_long_long), abs(max_long_long))
206
return c_long_long_abs(a)
208
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
209
"//ReturnStatNode//NameNode[@entry.cname = 'fabs']")
210
def double_abs(double a):
219
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
220
"//ReturnStatNode//NameNode[@entry.cname = 'fabs']")
221
cdef double c_double_abs(double a) nogil:
224
def test_c_double_abs(double a):
226
>>> test_c_double_abs(-5)
228
>>> test_c_double_abs(-5.5)
231
return c_double_abs(a)
233
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
234
"//ReturnStatNode//NameNode[@entry.cname = 'fabsf']")
235
def float_abs(float a):
244
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
245
"//ReturnStatNode//NameNode[@entry.cname = 'fabsf']")
246
cdef float c_float_abs(float a) nogil:
249
def test_c_float_abs(float a):
251
>>> test_c_float_abs(-5)
253
>>> test_c_float_abs(-5.5)
256
return c_float_abs(a)
258
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
259
"//ReturnStatNode//NameNode[@entry.cname = '__Pyx_c_abs_double']")
260
def complex_abs(complex a):
264
>>> complex_abs(-5.5j)
269
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']",
270
"//ReturnStatNode//NameNode[@entry.cname = '__Pyx_c_abs_double']")
271
cdef double c_complex_abs(complex a) nogil:
274
def test_c_complex_abs(complex a):
276
>>> test_c_complex_abs(-5j)
278
>>> test_c_complex_abs(-5.5j)
281
return c_complex_abs(a)