gh-162604: clarify NaN comparisons for Decimal's (#162639)
diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index 93eac90..14216f8 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst
@@ -1777,6 +1777,8 @@ 0 ** 0 x ** (non-integer) x ** Infinity + NaN >= 0 + NaN < 0 .. class:: Overflow @@ -1906,6 +1908,8 @@ Decimal('0.0060000') +.. _decimal-notes-specials: + Special values ^^^^^^^^^^^^^^
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index dba85db..97be69c 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst
@@ -2129,12 +2129,15 @@ involved, they compare mathematically (algorithmically) correct without loss of precision. - The not-a-number values ``float('NaN')`` and ``decimal.Decimal('NaN')`` are + The not-a-number floating-point numbers, like ``float('NaN')``, are special. Any ordered comparison of a number to a not-a-number value is false. A counter-intuitive implication is that not-a-number values are not equal to themselves. For example, if ``x = float('NaN')``, ``3 < x``, ``x < 3`` and ``x == x`` are all false, while ``x != x`` is true. This behavior is - compliant with IEEE 754. + compliant with IEEE 754. Similar behavior holds for + :class:`decimal.Decimal`'s not-a-number values, like ``Decimal('NaN')``. + Refer to the :ref:`Special values <decimal-notes-specials>` section + of the :mod:`decimal` documentation. * ``None`` and :data:`NotImplemented` are singletons. :PEP:`8` advises that comparisons for singletons should always be done with ``is`` or ``is not``,