Skip to content

Commit f018514

Browse files
skirpichevmiss-islington
authored andcommitted
gh-162604: clarify NaN comparisons for Decimal's (GH-162639)
(cherry picked from commit 5dbe2ac) Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
1 parent 65d8923 commit f018514

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
@@ -1728,6 +1728,8 @@ condition.
17281728
0 ** 0
17291729
x ** (non-integer)
17301730
x ** Infinity
1731+
NaN >= 0
1732+
NaN < 0
17311733

17321734

17331735
.. class:: Overflow
@@ -1857,6 +1859,8 @@ expanding the precision sufficiently to avoid loss of significance:
18571859
Decimal('0.0060000')
18581860

18591861

1862+
.. _decimal-notes-specials:
1863+
18601864
Special values
18611865
^^^^^^^^^^^^^^
18621866

‎Doc/reference/expressions.rst‎

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

1897-
The not-a-number values ``float('NaN')`` and ``decimal.Decimal('NaN')`` are
1897+
The not-a-number floating-point numbers, like ``float('NaN')``, are
18981898
special. Any ordered comparison of a number to a not-a-number value is false.
18991899
A counter-intuitive implication is that not-a-number values are not equal to
19001900
themselves. For example, if ``x = float('NaN')``, ``3 < x``, ``x < 3`` and
19011901
``x == x`` are all false, while ``x != x`` is true. This behavior is
1902-
compliant with IEEE 754.
1902+
compliant with IEEE 754. Similar behavior holds for
1903+
:class:`decimal.Decimal`'s not-a-number values, like ``Decimal('NaN')``.
1904+
Refer to the :ref:`Special values <decimal-notes-specials>` section
1905+
of the :mod:`decimal` documentation.
19031906

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

0 commit comments

Comments
 (0)