diff options
author | Charlie Zhao <zhaoyu_hit@qq.com> | 2022-04-03 03:58:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-02 12:58:03 -0700 |
commit | 182e93c3f57b0c72e765c9896066d32e461c0865 (patch) | |
tree | 80a268068e4270c15943fda2c7a4d68c31cd28e1 /Doc/library | |
parent | 208da6d508bb2683732151f4ae288dfc8001267c (diff) | |
download | cpython-git-182e93c3f57b0c72e765c9896066d32e461c0865.tar.gz |
bpo-47031: Improve documentation for `math.nan` (GH-32170)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/math.rst | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Doc/library/math.rst b/Doc/library/math.rst index bcbcdef51d..c0f9614231 100644 --- a/Doc/library/math.rst +++ b/Doc/library/math.rst @@ -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. |