[Haskell-cafe] Proper Handling of Exceptional IEEE Floating Point
Barak A. Pearlmutter
barak at cs.nuim.ie
Fri Apr 23 03:21:22 EDT 2010
> ... An invalid comparison evaluating to _|_ is arguably more
> correct, but I personally find the idea of introducing more bottoms
> rather distasteful.
Too late! NaN is pretty much the _|_ of IEEE Floating Point.
That was certainly the intent of the IEEE standard, and is why NaN is
so contagious. But they wanted to relax the usual strictness of their
languages (FORTRAN, C) when this particular _|_ is around. So NaN is
contagious through strict arithmetic (+, *, etc) like _|_. But it has
strange behaviour with respect to comparison. In the context of
Haskell, which does not have the issue of needing to relax strictness
just for NaN, I think the "right thing" would be to have compare give
_|_, and maybe also <, >, ==. After all, NaN is outside the carefully
defined total ordering of all other IEEE floating point values
including +/- Infinity.
(By the stringent criteria some people are giving for allowing
something to be Eq and Ord, Char would also be stripped of them, since
after all Char includes _|_. Sort of.)
More information about the Haskell-Cafe