Re: [Python-ideas] Re: Magnitude and ProtoMagnitude ABCs — primarily for argument validation

Alan Bawden alan at csail.mit.edu
Tue Mar 10 11:09:46 EDT 2020


Chris Angelico <rosuav at gmail.com> writes:
> People keep saying this - that nan exists to avoid exceptions - but
> that doesn't take signalling nans into account. Even in C, they are
> expected to raise an exception or equivalent.

Actually, its not that far from the truth to say that NaNs "exist to avoid
exceptions".  According to Kahan, NaNs were an improvement over previous
NaN-like mechanisms that existed in older computer hardware precisely
because they avoid exceptions.  Kahan says of those older mechanisms: "But
nobody used them because they trap when touched."

I believe that signalling NaNs were added to the IEEE standard late in the
process because people still wanted something you could store in a
uninitialized variable that would trap if you accidentally used it.  Unlike
all the IEEE operations that result in a NaN, using an uninitialized
variable is clearly an error.  Kahan doesn't think much of signalling NaNs,
writing that they "exist mainly for political reasons and are rarely used".

-- 
Alan Bawden


More information about the Python-list mailing list