closes bpo-28955: Clarified comparisons between NaN and number in ref… · python/cpython@ad8a000 (original) (raw)
`@@ -1336,12 +1336,11 @@ built-in types.
`
1336
1336
` involved, they compare mathematically (algorithmically) correct without loss
`
1337
1337
` of precision.
`
1338
1338
``
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.
1345
1344
``
1346
1345
`` * Binary sequences (instances of :class:bytes
or :class:bytearray
) can be
``
1347
1346
` compared within and across their types. They compare lexicographically using
`