A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-November/093910.html below:

[Python-Dev] decimal.py: == and != comparisons involving NaNs

[Python-Dev] decimal.py: == and != comparisons involving NaNsStefan Krah stefan-usenet at bytereef.org
Sun Nov 8 17:26:48 CET 2009
Hi,

in a (misguided) bugreport (http://bugs.python.org/issue7279) I was
questioning the reasons for allowing NaN comparisons with == and !=
rather than raising InvalidOperation.


I think two main issues emerge from the brief discussion:

1. Should the comparison operators follow the 'compare' function
   from the standard?

The standard says:

"An implementation may use this operation [compare] under the covers to
 implement a closed set of comparison operations (greater than, equal, etc.)
 if desired. It need not, in this case, expose the compare operation
 itself."

So, I'd say that this supports following 'compare' as closely as possible.
In fact the operators <, <=, >, >= already follow 'compare-signal' in
their behavior (they raise for any NaN operand).


2. What is the use of == and != outside the decimal scope?

Mark mentions that Python uses == to test for set and dict memberships,
but that you cannot put decimal NaNs into sets:

'TypeError: Cannot hash a NaN value'


I want to add that Decimal('NaN') == Decimal('NaN') gives False, which
should somewhat limit the uses of == for NaNs outside the decimal realm
anyway.


Are there cases where == and != are actually needed to give a result
for NaNs?


Stefan Krah



More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4