mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
closes bpo-28955: Clarified comparisons between NaN and number in reference documentation (GH-5982)
Co-authored-by: Benjamin Peterson <benjamin@python.org>
This commit is contained in:
parent
b93062b7fb
commit
ad8a000420
1 changed files with 5 additions and 6 deletions
|
|
@ -1336,12 +1336,11 @@ built-in types.
|
||||||
involved, they compare mathematically (algorithmically) correct without loss
|
involved, they compare mathematically (algorithmically) correct without loss
|
||||||
of precision.
|
of precision.
|
||||||
|
|
||||||
The not-a-number values :const:`float('NaN')` and :const:`Decimal('NaN')`
|
The not-a-number values ``float('NaN')`` and ``decimal.Decimal('NaN')`` are
|
||||||
are special. They are identical to themselves (``x is x`` is true) but
|
special. Any ordered comparison of a number to a not-a-number value is false.
|
||||||
are not equal to themselves (``x == x`` is false). Additionally,
|
A counter-intuitive implication is that not-a-number values are not equal to
|
||||||
comparing any number to a not-a-number value
|
themselves. For example, if ``x = float('NaN')``, ``3 < x``, ``x < 3``, ``x
|
||||||
will return ``False``. For example, both ``3 < float('NaN')`` and
|
== x``, ``x != x`` are all false. This behavior is compliant with IEEE 754.
|
||||||
``float('NaN') < 3`` will return ``False``.
|
|
||||||
|
|
||||||
* Binary sequences (instances of :class:`bytes` or :class:`bytearray`) can be
|
* Binary sequences (instances of :class:`bytes` or :class:`bytearray`) can be
|
||||||
compared within and across their types. They compare lexicographically using
|
compared within and across their types. They compare lexicographically using
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue