4 from cython cimport typeof
6 cdef extern from "arithmetic_analyse_types_helper.h":
7 cdef struct short_return:
9 cdef struct int_return:
11 cdef struct longlong_return:
13 cdef short_return f(short)
14 cdef int_return f(int)
15 cdef longlong_return f(long long)
17 def short_binop(short val):
19 Arithmetic in C is always done with at least int precision.
21 >>> print(short_binop(3))
24 assert typeof(val + val) == "int", typeof(val + val)
25 assert typeof(val - val) == "int", typeof(val - val)
26 assert typeof(val & val) == "int", typeof(val & val)
27 cdef int_return x = f(val + val)
28 return x.msg.decode('ASCII')
30 def short_unnop(short val):
32 Arithmetic in C is always done with at least int precision.
34 >>> print(short_unnop(3))
37 cdef int_return x = f(-val)
38 return x.msg.decode('ASCII')
40 def longlong_binop(long long val):
42 >>> print(longlong_binop(3))
45 cdef longlong_return x = f(val * val)
46 return x.msg.decode('ASCII')
48 def longlong_unnop(long long val):
50 >>> print(longlong_unnop(3))
53 cdef longlong_return x = f(~val)
54 return x.msg.decode('ASCII')
57 def test_bint(bint a):
61 assert typeof(a + a) == "int", typeof(a + a)
62 assert typeof(a & a) == "bint", typeof(a & a)