]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-47031: Improve documentation for `math.nan` (GH-32170)
authorCharlie Zhao <zhaoyu_hit@qq.com>
Sat, 2 Apr 2022 19:58:03 +0000 (03:58 +0800)
committerGitHub <noreply@github.com>
Sat, 2 Apr 2022 19:58:03 +0000 (12:58 -0700)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Doc/library/math.rst

index bcbcdef51d3fcb74a96edd2d54c041b020980dcf..c0f961423191223a8b39c2d79a2145b9b01182a2 100644 (file)
@@ -646,8 +646,23 @@ 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')``. 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 check
+   whether a number is a NaN, use the :func:`isnan` function to test
+   for NaNs instead of ``is`` or ``==``.
+   Example::
+
+      >>> import math
+      >>> math.nan == math.nan
+      False
+      >>> float('nan') == float('nan')
+      False
+      >>> math.isnan(math.nan)
+      True
+      >>> math.isnan(float('nan'))
+      True
 
    .. versionchanged:: 3.11
       It is now always available.