From: Charlie Zhao Date: Sat, 2 Apr 2022 19:58:03 +0000 (+0800) Subject: bpo-47031: Improve documentation for `math.nan` (GH-32170) X-Git-Tag: v3.11.0a7~52 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=182e93c3f57b0c72e765c9896066d32e461c0865;p=thirdparty%2FPython%2Fcpython.git bpo-47031: Improve documentation for `math.nan` (GH-32170) Co-authored-by: Jelle Zijlstra --- diff --git a/Doc/library/math.rst b/Doc/library/math.rst index bcbcdef51d3f..c0f961423191 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 + `_, ``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.