[Python-ideas] checking for identity before comparing built-in objects
rosuav at gmail.com
Mon Oct 8 02:42:28 CEST 2012
On Mon, Oct 8, 2012 at 11:35 AM, Alexander Belopolsky
<alexander.belopolsky at gmail.com> wrote:
> I am not suggesting any language changes, but I think it will be
> useful to explain why float('nan') != float('nan') somewhere in the
> docs. A reference to IEEE 754 does not help much. Java implements
> IEEE 754 to some extent, but preserves reflexivity of object equality.
NaN isn't a single value, but a whole category of values.
Conceptually, it's an uncountably infinite (I think that's the
technical term) of invalid results; in implementation, NaN has the
highest possible exponent and any non-zero mantissa.
So then the question becomes: Should *all* NaNs be equal, or only ones
with the same bit pattern? Aside from signalling vs non-signalling
NaNs, I don't think there's any difference between one and another, so
they should probably all compare equal. And once you go there, a huge
can o'worms is opened involving floating point equality.
It's much MUCH easier and simpler to defer to somebody else's standard
and just say "NaNs behave according to IEEE 754, blame them if you
don't like it". There would possibly be value in guaranteeing
reflexivity, but it would increase confusion somewhere else.
More information about the Python-ideas