Turn off ZeroDivisionError?

Dikkie Dik dikkie at nospam.org
Sun Feb 10 13:54:25 EST 2008


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.



More information about the Python-list mailing list