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

Dag Sverre Seljebotn dagss@student.matnat.uio...
Thu Mar 12 13:59:48 CDT 2009


(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

[ ] Get 4, because it should behave just like in Python, avoiding 
surprises when adding types to existing algorithms (this will require 
extra logic and be a bit slower)

[ ] Get -1, because they're C ints, and besides one isn't using
Cython if one doesn't care about performance

Whatever we do, this also affects the division operator, so that one in 
any case will have a==(a//b)*b+a%b.

(Orthogonal to this, we can introduce compiler directives to change the 
meaning of the operator from the default in a code blocks, and/or make 
special functions for the semantics that are not chosen as default.)

-- 
Dag Sverre


More information about the Numpy-discussion mailing list