Does Python defined the value of "NaN > 0"? In my Python interpreter, I get:
>>> float('nan') > 0
False
but is this guaranteed?
If I understand correctly, the IEEE 754 standard assigns False to any comparison involving NaN. However, I can't find anything in the Python documentation that indicates that this standard is followed. I even understand that 1/0
should give infinity, under IEEE 754, but Python raises an exception (ZeroDivisionError
), so Python does not fully follow IEEE 754.
So, is the result of float('nan') > 0
fully defined in Python? I need to know whether it is the same on all platforms, and with all versions of Python (including old ones).
All Python implementations that I've used on various platforms use IEEE-754 and would behave as you describe.
However, this does not appear to be formally mandated by the language. So much so that the tutorial has the following to say (emphasis mine):
Here is a relevant thread from 2008: Python on non IEEE-754 platforms: plea for information.
It is very easy to check whether your interpreter/platform behave the way you expect. If you're critically dependent on this, you could easily detect non-compliance when your program starts up.