This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: float('nan')==math.nan does NOT evaluate to True (as suggested by documentation).
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: JelleZijlstra, docs@python, eric.smith, w0rthle$$
Priority: normal Keywords:

Created on 2022-03-15 00:45 by w0rthle$$, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg415213 - (view) Author: Pablo Dumas (w0rthle$$) Date: 2022-03-15 00:45
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: https://docs.python.org/3.8/library/math.html
msg415214 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-03-15 01:05
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 worse) that's what the IEEE standard requires. You can instead use math.isnan() to check whether a number is a nan.
msg415215 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-03-15 01:21
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 wording that's confusing.
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91176
2022-03-15 01:21:51eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg415215

resolution: not a bug
stage: resolved
2022-03-15 01:05:59JelleZijlstrasetnosy: + JelleZijlstra
messages: + msg415214
2022-03-15 00:45:19w0rthle$$create