Author tim.peters
Recipients Rhamphoryncus, christian.heimes, gmcastil, gvanrossum, mark.dickinson, tim.peters
Date 2008-01-21.01:05:35
SpamBayes Score 0.00104452
Marked as misclassified No
Message-id <1200877536.97.0.0204421613917.issue1640@psf.upfronthosting.co.za>
In-reply-to
Content
Mark, these are the "spirit of 754" rules:

1. If the mathematical result is a real number, but of magnitude too
large to approximate by a machine float, overflow is signaled and the
result is an infinity (with the appropriate sign).

2. If the mathematical result is a real number, but of magnitude too
small to approximate by a machine float, underflow is signaled and the
result is a zero (with the appropriate sign).

3. At a singularity (a value x such that the limit of f(y) as y
approaches x exists and is an infinity), "divide by zero" is signaled
and the result is an infinity (with the appropriate sign).  This is
complicated a little by that the left-side and right-side limits may not
be the same; e.g., 1/x approaches +inf or -inf as x approaches 0 from
the positive or negative directions.  In that specific case, the sign of
the zero determines the result of 1/0.

4. At a point where a function has no defined result in the extended
reals (i.e., the reals plus an infinity or two), invalid operation is
signaled and a NaN is returned.

And these are what Python has historically /tried/ to do (but not always
successfully, as platform libm behavior varies a lot):

For #1, raise OverflowError.

For #2, return a zero (with the appropriate sign if that happens by
accident ;-)).

For #3 and #4, raise ValueError.  It may have made sense to raise
Python's ZeroDivisionError in #3, but historically that's only been
raised for division by zero and mod by zero.

You're right that you can't make everyone happy, so may as well stick
with historical consistency, and wait for a PEP to introduce a more
flexible mechanism.  As W. Kahan wrote long ago, the reason they're
called "exceptions" is that no matter which fixed policy you adopt,
someone will take strident exception to it ;-)
History
Date User Action Args
2008-01-21 01:05:37tim.peterssetspambayes_score: 0.00104452 -> 0.00104452
recipients: + tim.peters, gvanrossum, mark.dickinson, Rhamphoryncus, christian.heimes, gmcastil
2008-01-21 01:05:36tim.peterssetspambayes_score: 0.00104452 -> 0.00104452
messageid: <1200877536.97.0.0204421613917.issue1640@psf.upfronthosting.co.za>
2008-01-21 01:05:35tim.peterslinkissue1640 messages
2008-01-21 01:05:35tim.peterscreate