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.
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)
30 def short_unnop(short val):
32 Arithmetic in C is always done with at least int precision.
37 cdef int_return x = f(-val)
40 def longlong_binop(long long val):
45 cdef longlong_return x = f(val * val)
48 def longlong_unnop(long long val):
53 cdef longlong_return x = f(~val)
57 def test_bint(bint a):
61 assert typeof(a + a) == "int", typeof(a + a)
62 assert typeof(a & a) == "bint", typeof(a & a)