Turn off ZeroDivisionError?

Mark Dickinson dickinsm at gmail.com
Mon Feb 11 03:52:46 CET 2008


On Feb 10, 7:07 pm, Grant Edwards <gra... at visi.com> wrote:
> On 2008-02-10, Christian Heimes <li... at cheimes.de> wrote:
> >>>> from somemodule import ieee754
> >>>> with ieee754:
> > ...    r = a/0
> > ...    print r
> > inf
>
> That would be great.

Seriously, in some of my crazier moments I've considered trying to
write a PEP on this, so I'm very interested in figuring out exactly
what it is that people want.  The devil's in the details, but the
basic ideas would be:

(1) aim for consistent behaviour across platforms in preference to
exposing differences between platforms
(2) make default arithmetic raise Python exceptions in preference to
returning infs and nans.  Essentially, ValueError would be raised
anywhere that IEEE 754(r) specifies raising the divide-by-zero or
invalid signals, and OverflowError would be raised anywhere that IEEE
754(r) specifies raising the overflow signal.  The underflow and
inexact signals would be ignored.
(3) have a thread-local floating-point environment available from
Python to make it possible to turn nonstop mode on or off, with the
default being off.  Possibly make it possible to trap individual
flags.

Any thoughts on the general directions here?  It's far too late to
think about this for Python 2.6 or 3.0, but 3.1 might be a possibility.



More information about the Python-list mailing list