# Given two numeric types, return the narrowest type
# encompassing both of them.
if type1.is_enum and type2.is_enum:
- widest_type = c_int_type
- elif type2.rank > type1.rank:
- widest_type = type2
+ return c_int_type
+ elif type1 is type2:
+ return type1
+ elif (type1.signed and type2.signed) or (not type1.signed and not type2.signed):
+ if type2.rank > type1.rank:
+ return type2
+ else:
+ return type1
else:
- widest_type = type1
+ return sign_and_rank_to_type[min(type1.signed, type2.signed), max(type1.rank, type2.rank)]
return widest_type
def simple_c_type(signed, longness, name):
--- /dev/null
+__doc__ = """
+ >>> test_signed()
+ 3 <type 'int'>
+ 9 <type 'long'>
+ 6 <type 'long'>
+ 12 <type 'long'>
+"""
+
+
+cdef int i = 1
+cdef long l = 2
+cdef unsigned int ui = 4
+cdef unsigned long ul = 8
+
+def test_signed():
+ print i + l, type(i+l)
+ print i + ul, type(i+ul)
+ print ui + l, type(ui+l)
+ print ui + ul, type(ui+ul)