On Sat, Sep 12, 2020 at 05:48:30PM -0700, Paul Bryan wrote:
> I meant to ask, why is nan not comparable? Even:
> 
> >>> math.nan == math.nan
> False


It is worth explaining why the IEEE-754 standards committee agreed to 
make NANs unequal to everything.

"It is not possible to specify a fixed-size arithmetic type that 
satisfies all of the properties of real arithmetic that we know and 
love. The 754 committee has to decide to bend or break some of them. 
This is guided by some pretty simple principles:

1. When we can, we match the behavior of real arithmetic.

2. When we can't, we try to make the violations as predictable and as 
easy to diagnose as possible."

https://stackoverflow.com/a/1573715

Having NANs compare equal to NANs would lead to nonsensical results 
like:

* sqrt(-2) == sqrt(-3)
* 0.0/0.0 == acos(2.0)
* infinity - infinity == log(-1.0)

NANs represent an exceptional state in your calculation. Some wag once 
argued that these are exceptional cases because, no matter what we 
choose to do, someone will take exception to it. NANs are no exception 
(pun intended) and I think that there is no single right answer.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/S6MB3F5CCTSZ7XIDO2JRSPMI5I2ETKSM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to