1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
# ticket: t676
# tag: cpp
from cython cimport typeof
cdef extern from "arithmetic_analyse_types_helper.h":
cdef struct short_return:
char *msg
cdef struct int_return:
char *msg
cdef struct longlong_return:
char *msg
cdef short_return f(short)
cdef int_return f(int)
cdef longlong_return f(long long)
def short_binop(short val):
"""
Arithmetic in C is always done with at least int precision.
>>> print(short_binop(3))
int called
"""
assert typeof(val + val) == "int", typeof(val + val)
assert typeof(val - val) == "int", typeof(val - val)
assert typeof(val & val) == "int", typeof(val & val)
cdef int_return x = f(val + val)
return x.msg.decode('ASCII')
def short_unnop(short val):
"""
Arithmetic in C is always done with at least int precision.
>>> print(short_unnop(3))
int called
"""
cdef int_return x = f(-val)
return x.msg.decode('ASCII')
def longlong_binop(long long val):
"""
>>> print(longlong_binop(3))
long long called
"""
cdef longlong_return x = f(val * val)
return x.msg.decode('ASCII')
def longlong_unnop(long long val):
"""
>>> print(longlong_unnop(3))
long long called
"""
cdef longlong_return x = f(~val)
return x.msg.decode('ASCII')
def test_bint(bint a):
"""
>>> test_bint(True)
"""
assert typeof(a + a) == "int", typeof(a + a)
assert typeof(a & a) == "bint", typeof(a & a)
|