[Numpy-discussion] Poll: Semantics for % in Cython

Charles R Harris charlesr.harris@gmail....
Thu Mar 12 17:22:16 CDT 2009


On Thu, Mar 12, 2009 at 12:59 PM, Dag Sverre Seljebotn <
dagss@student.matnat.uio.no> wrote:

> (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
default.

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.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090312/de9c466f/attachment.html 


More information about the Numpy-discussion mailing list