[Numpy-discussion] Poll: Semantics for % in Cython
Dag Sverre Seljebotn
dagss@student.matnat.uio...
Fri Mar 13 03:27:09 CDT 2009
Fernando Perez wrote:
> On Thu, Mar 12, 2009 at 11:34 PM, Robert Kern <robert.kern@gmail.com> wrote:
>
>
>> One possibility (that may be opening a can of worms) is to have two
>> sets of operators, one that does "native" semantics (C for cdef longs,
>> Python for Python ints) and one that does Python semantics even on
>> cdef longs. I leave it to you to decide which one gets blessed with
>> "%" and which has to use the alternate ("~%"? there's a whole PEP
>> sitting around which goes over various options).
>>
>
> Without going into the whole pep 225 discussion, would it make sense
> for this particular case only, to consider instead a new %% operator?
>
This exact proposal was up on the Cython list. The fear was that if
Python decides to use this operator for something else in the future...
Please note that there are 3 different division operators:
- / under Py3/future import, which always returns float ("truediv")
- // (which is the same as / in Py2), which always floors the result,
i.e. -7 // 6 == -2
- The C /, which truncates the result, i.e. -7 / 6 == -1
So there's no directly corresponding pair of // and %% (one would need
to intrudoce /// or similar for C division in addition, in that case).
Dag Sverre
More information about the Numpy-discussion
mailing list