Annoying behaviour of the != operator
Max
rabkin at mweb[DOT]co[DOT]za
Thu Jun 23 15:02:26 EDT 2005
Jordan Rastrick wrote:
> I don't want to order the objects. I just want to be able to say if one
> is equal to the other.
>
> Here's the justification given:
>
> The == and != operators are not assumed to be each other's
> complement (e.g. IEEE 754 floating point numbers do not satisfy
> this). It is up to the type to implement this if desired.
> Similar for < and >=, or > and <=; there are lots of examples
> where these assumptions aren't true (e.g. tabnanny).
>
> Well, never, ever use equality or inequality operations with floating
> point numbers anyway, in any language, as they are notoriously
> unreliable due to the inherent inaccuracy of floating point. Thats
> another pitfall, I'll grant, but its a pretty well known one to anyone
> with programming experience. So I don't think thats a major use case.
>
I think this is referring to IEEE 754's NaN equality test, which
basically states that x==x is false if-and-only-if x.isNaN() is true.
More information about the Python-list
mailing list