| changeset 1152: |
f5f7c3df67d8 |
| parent 1151: | 3cd7a93fd553 |
| child 1153: | 61cf3db139ad |
| author: |
Robert Bradshaw <robertwb@math.washington.edu> |
| date: |
Sat Sep 13 20:29:53 2008 -0700 (3 months ago) |
| files: |
Cython/Compiler/PyrexTypes.py tests/run/unsigned.pyx |
| description: |
Unsigned arithmatic, ticket #54 |
--- a/Cython/Compiler/PyrexTypes.py Sat Sep 13 15:10:38 2008 -0700
+++ b/Cython/Compiler/PyrexTypes.py Sat Sep 13 20:29:53 2008 -0700
@@ -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):
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/run/unsigned.pyx Sat Sep 13 20:29:53 2008 -0700
@@ -0,0 +1,19 @@
+__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)