Why float('Nan') == float('Nan') is False
Chris Angelico
rosuav at gmail.com
Wed Feb 13 15:19:00 EST 2019
On Thu, Feb 14, 2019 at 7:12 AM Test Bot <onlinejudge95 at gmail.com> wrote:
>
> This definition of NaN is much better in mentally visualizing all the so
> called bizarreness of IEEE. This also makes intuitive that no 2 NaN will be
> equal just as no 2 infinities would be equal. I believe in a hypothesis(of
> my own creation) that any arithmetic on a data type of NaN would be similar
> to any set of operations on the set of Infinities.
>
Why would no two infinities be equal? In mathematics, there's one
best-known infinity (aleph null, aka the number of counting numbers),
and many many infinities are provably equal to it. (Others are
provably NOT equal to it, like the number of real numbers.) There's
nothing wrong with saying "there are as many prime numbers as there
are odd numbers", or equivalently that "the size/cardinality of the
set of primes is equal to the size of the set of odd numbers" [1]. And
both Python and IEEE agree:
>>> float("inf") == float("inf")
True
NaN and infinity are quite different concepts, and they behave very differently.
ChrisA
[1] I'm sure someone will point out something pedantically wrong in
what I said, but certainly the sets have the same cardinality.
More information about the Python-list
mailing list