Skip to content

Commit 5dbe2ac

Browse files
authored
gh-162604: clarify NaN comparisons for Decimal's (#162639)
1 parent ff9803a commit 5dbe2ac

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎Doc/library/decimal.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,8 @@ condition.
17771777
0 ** 0
17781778
x ** (non-integer)
17791779
x ** Infinity
1780+
NaN >= 0
1781+
NaN < 0
17801782

17811783

17821784
.. class:: Overflow
@@ -1906,6 +1908,8 @@ expanding the precision sufficiently to avoid loss of significance:
19061908
Decimal('0.0060000')
19071909

19081910

1911+
.. _decimal-notes-specials:
1912+
19091913
Special values
19101914
^^^^^^^^^^^^^^
19111915

‎Doc/reference/expressions.rst‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,12 +2129,15 @@ built-in types.
21292129
involved, they compare mathematically (algorithmically) correct without loss
21302130
of precision.
21312131

2132-
The not-a-number values ``float('NaN')`` and ``decimal.Decimal('NaN')`` are
2132+
The not-a-number floating-point numbers, like ``float('NaN')``, are
21332133
special. Any ordered comparison of a number to a not-a-number value is false.
21342134
A counter-intuitive implication is that not-a-number values are not equal to
21352135
themselves. For example, if ``x = float('NaN')``, ``3 < x``, ``x < 3`` and
21362136
``x == x`` are all false, while ``x != x`` is true. This behavior is
2137-
compliant with IEEE 754.
2137+
compliant with IEEE 754. Similar behavior holds for
2138+
:class:`decimal.Decimal`'s not-a-number values, like ``Decimal('NaN')``.
2139+
Refer to the :ref:`Special values <decimal-notes-specials>` section
2140+
of the :mod:`decimal` documentation.
21382141

21392142
* ``None`` and :data:`NotImplemented` are singletons. :PEP:`8` advises that
21402143
comparisons for singletons should always be done with ``is`` or ``is not``,

0 commit comments

Comments
 (0)