Skip to content

Commit 182e93c

Browse files
bpo-47031: Improve documentation for math.nan (GH-32170)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 208da6d commit 182e93c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Doc/library/math.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,23 @@ Constants
646646

647647
.. data:: nan
648648

649-
A floating-point "not a number" (NaN) value. Equivalent to the output of
650-
``float('nan')``.
649+
A floating-point "not a number" (NaN) value. Equivalent to the output of
650+
``float('nan')``. Due to the requirements of the `IEEE-754 standard
651+
<https://en.wikipedia.org/wiki/IEEE_754>`_, ``math.nan`` and ``float('nan')`` are
652+
not considered to equal to any other numeric value, including themselves. To check
653+
whether a number is a NaN, use the :func:`isnan` function to test
654+
for NaNs instead of ``is`` or ``==``.
655+
Example::
656+
657+
>>> import math
658+
>>> math.nan == math.nan
659+
False
660+
>>> float('nan') == float('nan')
661+
False
662+
>>> math.isnan(math.nan)
663+
True
664+
>>> math.isnan(float('nan'))
665+
True
651666

652667
.. versionchanged:: 3.11
653668
It is now always available.

0 commit comments

Comments
 (0)