From: Robert Bradshaw Date: Sun, 14 Sep 2008 03:29:53 +0000 (-0700) Subject: Unsigned arithmatic, ticket #54 X-Git-Tag: 0.9.9.2.beta~95^2~7 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7b3554bdba45c6b3f4b4f4366abba6c368b72adb;p=cython.git Unsigned arithmatic, ticket #54 --- diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 263abb57..682c4741 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1181,11 +1181,16 @@ def widest_numeric_type(type1, type2): # 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): diff --git a/tests/run/unsigned.pyx b/tests/run/unsigned.pyx new file mode 100644 index 00000000..86d2cda7 --- /dev/null +++ b/tests/run/unsigned.pyx @@ -0,0 +1,19 @@ +__doc__ = """ + >>> test_signed() + 3 + 9 + 6 + 12 +""" + + +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)