You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def max_test():
cdef unsigned int x = 0
cdef int smid = 4
print(x,smid - x, -smid, max(smid - x, -smid))
Running this function prints:
(0, 4, -4, 4294967292)
I would expect it to print:
(0, 4, -4, 4)
Although from a C point of view the "worng" result may be the right one. However, then smid - x should be printed as 4294967292.
Either way, note that this behavior causes the fully optimized example on: http://docs.cython.org/src/tutorial/numpy.html
to break. Presumably this example worked with older cython versions.
Note that the unexpected last value that you see is not the result of "smid-x" but the unsigned result of "-smid", because the unsigned (and thus wrapped around) result of "-smid" is actually way bigger than the unsigned result of "smid-x", which is just 4.
I'm not sure if this is really a bug. Mixing signed and unsigned integer types is worth the C compiler warning that this code gives me, and using unsigned values to subtract them from signed values mostly screams for trouble. That fact that you seem to have misinterpreted the (certainly non-ovious) result speaks volumes, I think.
Running this function prints:
(0, 4, -4, 4294967292)
I would expect it to print:
(0, 4, -4, 4)
Although from a C point of view the "worng" result may be the right one. However, then smid - x should be printed as 4294967292.
Either way, note that this behavior causes the fully optimized example on:
http://docs.cython.org/src/tutorial/numpy.html
to break. Presumably this example worked with older cython versions.
Migrated from http://trac.cython.org/ticket/772
The text was updated successfully, but these errors were encountered: