[Tutor] Implementation of list comparison operators

Steven D'Aprano steve at pearwood.info
Thu Jan 17 17:01:34 EST 2019


On Thu, Jan 17, 2019 at 03:05:17PM -0600, David Rock wrote:

> In [7]: nan == nan
> Out[7]: False
> 
> In [8]: a = 1.1
> 
> In [9]: a ==a
> Out[9]: True


> both a and nan are floats, so why does a == a work, but nan == nan 
> doesn’t?

They both "work", because they both do what they are designed to do.

Equality between two floats works something like this:

    if either number is a NAN:
        return False
    if both numbers are 0.0 or -0.0:
        return True
    if both numbers have the same bit-pattern:
        return True
    otherwise return False


-- 
Steve


More information about the Tutor mailing list