bpo-47031: Improve documentation for math.nan (GH-32170)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Charlie Zhao 2022-04-03 03:58:03 +08:00 committed by GitHub
parent 208da6d508
commit 182e93c3f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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.