[Numpy-discussion] Poll: Semantics for % in Cython
Charles R Harris
Thu Mar 12 17:22:16 CDT 2009
On Thu, Mar 12, 2009 at 12:59 PM, Dag Sverre Seljebotn <
> (First off, is it OK to continue polling the NumPy list now and then on
> Cython language decisions? Or should I expect that any interested Cython
> users follow the Cython list?)
> In Python, if I write "-1 % 5", I get 4. However, in C if I write "-1 %
> 5" I get -1. The question is, what should I get in Cython if I write (a
> % b) where a and b are cdef ints? Should I
I almost always want the python version, even in C, because I want the
results to lie in the interval [0,5) like a good modulus functions should ;)
I suppose the question is : is '%' standing for the modulus or is it
standing for the remainder in whatever version of division is being used.
This is similar to the difference between the trunc and floor functions; I
find using the floor function causes fewer problems, but it isn't the
That said, I think it best to leave '%' with its C default and add a special
modulus function for the python version. Changing its meaning in C-like code
is going to confuse things.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion