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
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."
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.