Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 319a70c

Browse files
bpo-47031: Improve documentation for math.nan (GH-32170)
Co-authored-by: Jelle Zijlstra <[email protected]> (cherry picked from commit 182e93c) Co-authored-by: Charlie Zhao <[email protected]>
1 parent 5830a28 commit 319a70c

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
@@ -627,8 +627,23 @@ Constants
627627

628628
.. data:: nan
629629

630-
A floating-point "not a number" (NaN) value. Equivalent to the output of
631-
``float('nan')``.
630+
A floating-point "not a number" (NaN) value. Equivalent to the output of
631+
``float('nan')``. Due to the requirements of the `IEEE-754 standard
632+
<https://en.wikipedia.org/wiki/IEEE_754>`_, ``math.nan`` and ``float('nan')`` are
633+
not considered to equal to any other numeric value, including themselves. To check
634+
whether a number is a NaN, use the :func:`isnan` function to test
635+
for NaNs instead of ``is`` or ``==``.
636+
Example::
637+
638+
>>> import math
639+
>>> math.nan == math.nan
640+
False
641+
>>> float('nan') == float('nan')
642+
False
643+
>>> math.isnan(math.nan)
644+
True
645+
>>> math.isnan(float('nan'))
646+
True
632647

633648
.. versionadded:: 3.5
634649

0 commit comments

Comments
 (0)