two case studies of NaN

27 points by seb


kghose

I love things like this that repro with a few lines of code and are fundamental.

In terms of sociology, I suspect if your inputs hit these values you add guards for them over time (and probably get good at preemptive guards and tests as you gain experience)

I wonder if not having the guards in the language implementation was a conscious decision (leave it as a user space decision) now lost to time.

FRIGN

To give a bit of context, NaN != NaN is an artifact from back when IEEE 754 was very young and the standard did not yet specify an isnan() function. Instead, one was supposed to identify a NaN by comparing it to itself.

In the meantime, IEEE 754 has included a so-called total order predicate, an alternative ordering. Using this predicate, NaN == NaN holds, and I think it's a sane choice.

chrismorgan

to be clear, i'm not necessarily saying that python's behavior here is wrong, or that this optimization is bad because NaN behaves weirdly.

Why not? It clearly is wrong. Maybe that wrongness is considered acceptable, but I don’t think you could reasonably argue that it isn’t wrong.