Eric V. Smith added the comment:
Jelle gives the correct reason for what you're seeing.
Also note:
>>> math.nan == math.nan
False
>>> float('nan') == float('nan')
False
If there's some specific part of the documentation that you think is
misleading, please reopen this and point us to the
Jelle Zijlstra added the comment:
I'm guessing you're referring to
https://docs.python.org/3.8/library/math.html#math.nan. The text says
explicitly that math.nan is "equivalent" to float("nan"), not that it is equal.
This is correct.
nan is not equal to itself, because (for better or
New submission from Pablo Dumas :
float('nan')==math.nan does NOT evaluate to True (as suggested by
documentation).
On the other hand, float('inf')==math.inf DOES evaluate to True (as
suggested by documentation).
Documentation we're referring to: