Caveats
Since Cython mixes C and Python semantics, some things may be a bitsurprising or unintuitive. Work always goes on to make Cython more naturalfor Python users, so this list may change in the future.
- Given two typed
int
variablesa
andb
,a % b
has the
same sign as the second argument (following Python semantics) rather than
having the same sign as the first (as in C). The C behavior can be
obtained, at some speed gain, by enabling the cdivision directive
(versions prior to Cython 0.12 always followed C semantics).- Care is needed with unsigned types.
cdef unsigned n = 10;
will print an empty list, since
print(range(-n, n))-n
wraps
around to a large positive integer prior to being passed to therange
function.- Python’s
float
type actually wraps Cdouble
values, and
theint
type in Python 2.x wraps Clong
values.