Numerics, NaNs, IEEE 754 and C99

Nick Maclaren nmm1 at cus.cam.ac.uk
Wed Jun 14 13:21:23 EDT 2006


In article <mailman.7040.1150302496.27775.python-list at python.org>,
Gary Herron <gherron at islandtraining.com> writes:
|> Christophe wrote:
|> > Grant Edwards a =E9crit :
|> >
|> >> The division by zero trap is really annoying.  In my world the
|> >> right thing to do is to return Inf.
|> >
|> > Your world is flawed then, this is a big mistake. NaN is the only=20
|> > aceptable return value for a division by zero.
|> >
|> Sorry, but this is not true.
|> 
|> The IEEE standard specifies (plus or minus) infinity as the result of
|> division by zero.  This makes sense since such is the limit of division
|> by a quantity that goes to zero.  The IEEE standard then goes on to
|> define reasonable results for arithmetic between infinities and real
|> values.  The production of, and arithmetic on, infinities is a choice
|> that any application may want allow or not.

That is true, and it is numerical nonsense.  Christophe is right.  Despite
Kahan's eminence as a numerical analyst, he is no software engineer.  And
I am amazed at ANY engineer that can believe that inverting zero should
give infinity - while there ARE circumstances where it is correct, it is
NEVER a safe thing to do by default.

The reason is that it is correct only when you know for certain that the
sign of zero is meaningful.  IEEE 754 gets this wrong by conflating true
zero, sign-unknown zero and positive zero.  Inter alia, it means that
you get situations like:

    A = 0.0; B = -A; C = B+0.0; A == B == C; 1/A != 1/B != 1/C;


Regards,
Nick Maclaren.



More information about the Python-list mailing list