[Python-Dev] decimal.py: == and != comparisons involving NaNs
by Stefan Krah other posts by this author
Nov 8 2009 8:31AM messages near this date
Re: [Python-Dev] raw binary data and 2to3
|
Re: [Python-Dev] decimal.py: == and != comparisons involving NaNs
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
_______________________________________________
Python-Dev mailing list
Python-Dev@[...].org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-dev-ml%40maillist.acti
vestate.com
Thread:
Stefan Krah
Mark Dickinson
Adam Olsen
Mark Dickinson
Mark Dickinson
Adam Olsen
Antoine Pitrou
Mark Dickinson
Raymond Hettinger
Antoine Pitrou
Stefan Krah
Mark Dickinson
Terry Reedy
Guido van Rossum
Antoine Pitrou
Greg Ewing
Stefan Krah
Mark Dickinson
Stefan Krah
Mark Dickinson
Antoine Pitrou
Robert Kern
|