On Apr 14, 2009, at 1:04 PM, Carl Witty wrote:

> On Tue, Apr 14, 2009 at 11:53 AM, Robert Bradshaw
> <[email protected]> wrote:
>> On Apr 14, 2009, at 9:17 AM, Dag Sverre Seljebotn wrote:
>>
>>> I was just thinking about this:
>>>
>>>      cdef int a = 10, b = 0
>>>      print a // b
>>>
>>> which currently gives a C exception terminating the Python
>>> interpreter.
>>>
>>> On one hand: We have already changed division to Python behaviour
>>> (with
>>> a speed penalty); so using the same arguments (which I won't
>>> reiterate)
>>> it would make sense to raise a Python exception instead here.
>>>
>>> It seems to make sense to couple this as well to the cdivision
>>> directive
>>> and cython.cdiv function.
>>>
>>> On the other hand: Well, all the arguments that was against
>>> changing //
>>> to Python behaviour.
>>
>> Since we changed it, we should chang it all the way. It will be
>> somewhat uglier as this means when writing a / (c-c) one needs to
>> store the denominator in a temp and check it rather than simply
>> letting the expression through to C (I already did this for  
>> warnings).

OK, pushed. http://hg.cython.org/cython-devel/rev/a09a309febdc

> If we're going through and listing special cases for division, there's
> one more to consider (I think this is the last one):
>
> On x86 processors, dividing -2**31 by -1 gives a processor signal;
> under Linux, this results in exiting the process with "Floating point
> exception".  (Even though it's not floating point.)  (Presumably, the
> same thing happens when dividing -2**63 by -1 on a 64-bit processor; I
> haven't tested.)

Interesting corner case. This seems more like an overflow issue, and  
we're currently not trying to protect the user from those.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to