Turn off ZeroDivisionError?

Steve Holden steve at holdenweb.com
Sun Feb 10 15:31:07 EST 2008


Dikkie Dik wrote:
> Mark Dickinson wrote:
>> On Feb 9, 5:03 pm, Neal Becker <ndbeck... at gmail.com> wrote:
>>> If I use C code to turn off the hardware signal, will that stop python from
>>> detecting the exception, or is python checking for 0 denominator on it's
>>> own (hope not, that would waste cycles).
>> Yes, Python does do an explicit check for a zero denominator.  Here's
>> an excerpt from floatdiv.c in Objects/floatobject.c:
>>
>> if (b == 0.0) {
>>     PyErr_SetString(PyExc_ZeroDivisionError, "float division");
>>     return NULL;
>> }
>>
>> This is probably the only sane way to deal with differences in
>> platform behaviour when doing float divisions.
> Are you sure?
> 
> It could very well be that 1/(smallest possible number)>(greatest 
> possible number). So I would also trap any errors besides trapping for 
> the obvious zero division.

What's so special about one? You surely don't expect the Python code to 
check for all possible cases of overflow before allowing the hardware to 
proceed with a division?

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list