Turn off ZeroDivisionError?

Ben Finney bignose+hates-spam at benfinney.id.au
Sun Feb 10 17:50:07 EST 2008


Mark Dickinson <dickinsm at gmail.com> writes:

> On Feb 10, 3:29 pm, Grant Edwards <gra... at visi.com> wrote:
> > platform does".  Except it doesn't in cases like this. All my
> > platforms do exactly what I want for division by zero: they
> > generate a properly signed INF.  Python chooses to override
> > that (IMO correct) platform behavior with something surprising.
> > Python doesn't generate exceptions for other floating point
> > "events" -- why the inconsistency with divide by zero?
> 
> But not everyone wants 1./0. to produce an infinity;  some people
> would prefer an exception.

Special cases aren't special enough to break the rules.

Most people would not want this behaviour either::

    >>> 0.1
    0.10000000000000001

But the justification for this violation of surprise is "Python just
does whatever the underlying hardware does with floating-point
numbers". If that's the rule, it shouldn't be broken in the special
case of division by zero.

-- 
 \      “If the desire to kill and the opportunity to kill came always |
  `\      together, who would escape hanging?” —Mark Twain, _Following |
_o__)                                                     the Equator_ |
Ben Finney



More information about the Python-list mailing list