As commented by @user2357112 #cython: cdivision=True
contradicts from __future__ import division
. This code is illustrative:
#cython: wraparound=False
#cython: boundscheck=False
#cython: nonecheck=False
#cython: profile=False
from __future__ import division
def main():
cdef double i, j
i = 0
j = 2
print 1/j
print 1/i
print 1/2
raising:
print 1/i
ZeroDivisionError: float division
Adding #cython: cdivision=True
it will give:
0.5
inf
0
where you can see the 1/2
being processed as a floor division.
In this case I would recommend to apply the float point 1/2.
wherever you want a float division when using Python 2.x...
Swapping the lines as you mentioned:
from __future__ import division
#cython: wraparound=False
#cython: boundscheck=False
#cython: nonecheck=False
#cython: profile=False
#cython: cdivision=True
will cancel all the Cython global directives, because they "must appear before any code (but can appear after other comments or whitespace)".