From 319a70cf99c9866c7fa47deecf04f6ebcfe35a54 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sat, 2 Apr 2022 13:19:20 -0700 Subject: [PATCH] bpo-47031: Improve documentation for `math.nan` (GH-32170) Co-authored-by: Jelle Zijlstra (cherry picked from commit 182e93c3f57b0c72e765c9896066d32e461c0865) Co-authored-by: Charlie Zhao --- Doc/library/math.rst | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Doc/library/math.rst b/Doc/library/math.rst index 145bac4966e1..d485ae5c2706 100644 --- a/Doc/library/math.rst +++ b/Doc/library/math.rst @@ -627,8 +627,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 + `_, ``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 .. versionadded:: 3.5 -- 2.47.3