Skip to content

Commit ad8a000

Browse files
TonyFlurybenjaminp
andcommitted
closes bpo-28955: Clarified comparisons between NaN and number in reference documentation (GH-5982)
Co-authored-by: Benjamin Peterson <[email protected]>
1 parent b93062b commit ad8a000

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Doc/reference/expressions.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,12 +1336,11 @@ built-in types.
13361336
involved, they compare mathematically (algorithmically) correct without loss
13371337
of precision.
13381338

1339-
The not-a-number values :const:`float('NaN')` and :const:`Decimal('NaN')`
1340-
are special. They are identical to themselves (``x is x`` is true) but
1341-
are not equal to themselves (``x == x`` is false). Additionally,
1342-
comparing any number to a not-a-number value
1343-
will return ``False``. For example, both ``3 < float('NaN')`` and
1344-
``float('NaN') < 3`` will return ``False``.
1339+
The not-a-number values ``float('NaN')`` and ``decimal.Decimal('NaN')`` are
1340+
special. Any ordered comparison of a number to a not-a-number value is false.
1341+
A counter-intuitive implication is that not-a-number values are not equal to
1342+
themselves. For example, if ``x = float('NaN')``, ``3 < x``, ``x < 3``, ``x
1343+
== x``, ``x != x`` are all false. This behavior is compliant with IEEE 754.
13451344

13461345
* Binary sequences (instances of :class:`bytes` or :class:`bytearray`) can be
13471346
compared within and across their types. They compare lexicographically using

0 commit comments

Comments
 (0)