[Haskell-cafe] Exception for NaN

Daniel Fischer daniel.is.fischer at googlemail.com
Sat May 14 17:42:24 CEST 2011


On Saturday 14 May 2011 15:14:31, Ketil Malde wrote:
> Daniel Fischer <daniel.is.fischer at googlemail.com> writes:
> > Not having Eq and Ord instances for Double and Float would be
> > extremely inconvenient (too inconvenient to seriously consider, I
> > think), so one can a) do what's done now
> > b) make NaNs an error
> > c) come up with a brilliant solution.
> 
> Maybe not terribly brilliant, but wouldn't it improve things slightly if
> NaN was considered less or greater than any other value (possibly
> excluding infinities)?

On the one hand yes, although it would be arbitrary and still produce 
undesirable results.

On the other hand, the behaviour of (==), (<) etc. with NaNs that we have 
is what is specified in the Java Language Specification (section 4.2.3) and 
in the C99 standard (fn. 206, §17.12.14.2 and Appendix F.8.3), if I read 
that footnote correctly, that behaviour is required by IEC 60559 (by which 
comparisons involving a NaN must raise an 'invalid' exception). I expect 
that other languages specify the same behaviour, I think it's what the 
hardware does.

So, is it worth changing? I'm not sure, but I tend towards thinking it's 
not, we'd need a better solution to make it worth the deviation.



More information about the Haskell-Cafe mailing list