-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-47031: Improve documentation for math.nan
#32170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -646,8 +646,27 @@ Constants | |
|
||
.. data:: nan | ||
|
||
A floating-point "not a number" (NaN) value. Equivalent to the output of | ||
``float('nan')``. | ||
A floating-point "not a number" (NaN) value. Equivalent to the output of | ||
``float('nan')``. Specifically, due to the requirements of the `IEEE-754 standard | ||
<https://en.wikipedia.org/wiki/IEEE_754>`_, ``math.nan`` and ``float('nan')`` are | ||
not considered to equal to any other numeric value, including themselves. To avoid errors | ||
when checking whether a number is a NaN, use the :func:`isnan` function to test | ||
CharlieZhao95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for NaNs instead of ``is`` or ``==``. | ||
Example:: | ||
|
||
>>> import math | ||
>>> math.nan == math.nan | ||
False | ||
>>> float('nan') == float('nan') | ||
False | ||
>>> math.nan is math.nan | ||
True | ||
>>> float('nan') is float('nan') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not too happy about this example because I could see us change this behavior in the future to return the same NaN object. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I feel the same way, this example is confusing. This phenomenon is simply due to the differences in function implementations, not related to any standard. Maybe we should omit the example about |
||
False | ||
>>> math.isnan(math.nan) | ||
True | ||
>>> math.isnan(float('nan')) | ||
True | ||
|
||
.. versionchanged:: 3.11 | ||
It is now always available. | ||
|
Uh oh!
There was an error while loading. Please reload this page.