From 7b3554bdba45c6b3f4b4f4366abba6c368b72adb Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sat, 13 Sep 2008 20:29:53 -0700 Subject: [PATCH] Unsigned arithmatic, ticket #54 --- Cython/Compiler/PyrexTypes.py | 13 +++++++++---- tests/run/unsigned.pyx | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 tests/run/unsigned.pyx 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) -- 2.26.2