Numeric comparison anomaly

sismex01 at hebmex.com sismex01 at hebmex.com
Thu Feb 20 16:18:13 EST 2003


> From: Piet van Oostrum [mailto:piet at cs.uu.nl]
> Sent: Thursday, February 20, 2003 3:14 PM
> 
> >>>>> sismex01 at hebmex.com (S) wrote:
>  
> >> From: Piet van Oostrum [mailto:piet at cs.uu.nl]
> >> Sent: Thursday, February 20, 2003 4:56 AM
> >> 
> >> >>>>> Gerrit Holl <gerrit at nl.linux.org> (GH) schreef:
> >> 
> GH> You can use the __cmp__ overloader:
> >> 
> GH> 21 >>> class A:
> GH> 21 ...  def __cmp__(self, other):
> GH> 21 ...   return 1
> GH> 21 ...
> GH> 22 >>> A() > 5
> GH> True
> GH> 23 >>> A() < 9
> GH> False
> GH> 24 >>> A() >= 3
> GH> True
> >> 
> >> >>> inf = A()
> >> >>> inf > inf
> >> True
> >> >>> inf == inf
> >> False
> >> >>> 
> >> 
> 
> S> This is correct, or wrong?
> 
> I would consider that incorrect. But others may differ. But if it is
> considered correct, then > is not an ordering for sets that 
> include inf.
> On the other hand, in Python > isn't an ordering in general.
> -- 

If __cmp__() returns 1, then "inf == inf" can't ever be true,
because __cmp__() is actually saying that it's larger.

-gustavo






More information about the Python-list mailing list