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

2009-11-13 Thread Adam Olsen
On Mon, Nov 9, 2009 at 06:01, Mark Dickinson dicki...@gmail.com wrote: Well, when running in some form of 'non-stop' mode, where (quiet) NaN results are supposed to be propagated to the end of a computation, you certainly want equality comparisons with nan just to silently return false. E.g.,

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

2009-11-13 Thread Mark Dickinson
On Fri, Nov 13, 2009 at 6:18 PM, Adam Olsen rha...@gmail.com wrote: On Mon, Nov 9, 2009 at 06:01, Mark Dickinson dicki...@gmail.com wrote: Well, when running in some form of 'non-stop' mode, where (quiet) NaN results are supposed to be propagated to the end of a computation, you certainly want

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

2009-11-13 Thread Mark Dickinson
On Fri, Nov 13, 2009 at 9:50 PM, Mark Dickinson dicki...@gmail.com wrote: And they do:  nan != 0 returns False.  Maybe I'm missing your point here? Aargh! True! I meant to say True! Mark ___ Python-Dev mailing list Python-Dev@python.org

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

2009-11-13 Thread Adam Olsen
On Fri, Nov 13, 2009 at 14:52, Mark Dickinson dicki...@gmail.com wrote: On Fri, Nov 13, 2009 at 9:50 PM, Mark Dickinson dicki...@gmail.com wrote: And they do:  nan != 0 returns False.  Maybe I'm missing your point here? Aargh!  True!  I meant to say True! Huh. Somewhere along the line I

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

2009-11-09 Thread Stefan Krah
Raymond Hettinger pyt...@rcn.com wrote: [Stefan Krah] in a (misguided) bugreport (http://bugs.python.org/issue7279) I was questioning the reasons for allowing NaN comparisons with == and != rather than raising InvalidOperation. Do you have any actual use case issues or are these theoretical

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

2009-11-09 Thread Antoine Pitrou
Stefan Krah stefan-usenet at bytereef.org writes: d = {0:Decimal(NaN)} Decimal(NaN) in d.values() False So, since non-decimal use cases are limited at best, the equality/inequality operators might as well have the behavior of the other comparison operators, which is safer for the user.

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

2009-11-09 Thread Stefan Krah
Antoine Pitrou solip...@pitrou.net wrote: Stefan Krah stefan-usenet at bytereef.org writes: d = {0:Decimal(NaN)} Decimal(NaN) in d.values() False So, since non-decimal use cases are limited at best, the equality/inequality operators might as well have the behavior of the other

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

2009-11-09 Thread Antoine Pitrou
Stefan Krah stefan-usenet at bytereef.org writes: I see the point, but Decimal(NaN) does not hash: Ok but witness again: L = [1, 2, Decimal(NaN), 3] 3 in L True class H(object): ... def __eq__(self, other): raise ValueError ... L = [1, 2, H(), 3] 3 in L Traceback (most recent call

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

2009-11-09 Thread Mark Dickinson
On Mon, Nov 9, 2009 at 12:21 PM, Stefan Krah stefan-use...@bytereef.org wrote: I see the point, but Decimal(NaN) does not hash: hash(Decimal(NaN)) Traceback (most recent call last):  File stdin, line 1, in module  File /usr/lib/python2.7/decimal.py, line 937, in __hash__    raise

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

2009-11-09 Thread Mark Dickinson
On Sun, Nov 8, 2009 at 4:26 PM, Stefan Krah stefan-use...@bytereef.org wrote: 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. Some quick recent history: For

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

2009-11-09 Thread Mark Dickinson
On Mon, Nov 9, 2009 at 10:42 AM, Stefan Krah stefan-use...@bytereef.org wrote: I can also give a decimal use case where the current behavior is problematic A variable initialized to a signaling NaN should always cause an exception. But this doesn't: salary = Decimal(sNaN) minimum_wage =

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

2009-11-09 Thread Stefan Krah
Antoine Pitrou solip...@pitrou.net wrote: I see the point, but Decimal(NaN) does not hash: Ok but witness again: L = [1, 2, Decimal(NaN), 3] 3 in L True class H(object): ... def __eq__(self, other): raise ValueError ... L = [1, 2, H(), 3] 3 in L Traceback (most recent call

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

2009-11-09 Thread Mark Dickinson
On Mon, Nov 9, 2009 at 1:01 PM, Mark Dickinson dicki...@gmail.com wrote: current behaviour comes from the IEEE 854 standard;  given the absence of helpful information in the Decimal standard, IEEE 854 is an obvious next place to look.  There's an unofficial copy of the standard available at:

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

2009-11-09 Thread Mark Dickinson
On Mon, Nov 9, 2009 at 1:21 PM, Stefan Krah stefan-use...@bytereef.org wrote: Antoine Pitrou solip...@pitrou.net wrote: (NB: interestingly, float(nan) does hash) I wonder if it should: d = {float('nan'): 10, 0: 20} 0 in d True float('nan') in d False d[float('nan')] Traceback (most

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

2009-11-09 Thread Antoine Pitrou
Stefan Krah stefan-usenet at bytereef.org writes: I guess my point is that NaNs in lists and dicts are broken in so many ways that it might be good to discourage this use. (And get the added benefit of safer mathematical behavior for == and !=.) Giving users seemingly random and

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

2009-11-09 Thread Greg Ewing
Antoine Pitrou wrote: The problem is when searching for /another/ object which hashes the same as Decimal(NaN). Maybe decimal NaNs should be unhashable, so that you can't put them in a dictionary in the first place. -- Greg ___ Python-Dev mailing

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

2009-11-09 Thread Terry Reedy
Mark Dickinson wrote: That's because you're creating two different float nans. Compare with: Python 3.2a0 (py3k:76132M, Nov 6 2009, 14:47:39) [GCC 4.2.1 (SUSE Linux)] on linux2 Type help, copyright, credits or license for more information. nan = float('nan') d = {nan: 10, 0: 20} nan in d

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

2009-11-09 Thread Guido van Rossum
On Mon, Nov 9, 2009 at 2:51 PM, Terry Reedy tjre...@udel.edu wrote: This also suggests to me that nan should be a singleton, or at least that the doc should recommend that programs should make it be such for the program. The IEEE std disagreed -- there's extra info hidden in the mantissa bits.

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

2009-11-08 Thread Stefan Krah
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'

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

2009-11-08 Thread Raymond Hettinger
[Stefan Krah] in a (misguided) bugreport (http://bugs.python.org/issue7279) I was questioning the reasons for allowing NaN comparisons with == and != rather than raising InvalidOperation. Do you have any actual use case issues or are these theoretical musings? I ask only because a good use

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

2009-11-08 Thread Antoine Pitrou
Stefan Krah stefan-usenet at bytereef.org writes: Are there cases where == and != are actually needed to give a result for NaNs? It is a common expectation that == and != always succeed. They return True or False, but don't raise an exception even on unrelated operands: ba == a False 5 ==

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

2009-11-08 Thread Robert Kern
Antoine Pitrou wrote: Stefan Krah stefan-usenet at bytereef.org writes: Are there cases where == and != are actually needed to give a result for NaNs? It is a common expectation that == and != always succeed. They return True or False, but don't raise an exception even on unrelated operands: