int nan

dsimcha dsimcha at yahoo.com
Fri Jun 26 12:57:07 PDT 2009


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> The following comes partially from a friend of mine. If you are busy you can
skip this post of musings.
> From the docs:
> http://www.digitalmars.com/d/1.0/faq.html#nan
> >Because of the way CPUs are designed, there is no NaN value for integers, so D
uses 0 instead. It doesn't have the advantages of error detection that NaN has,
but at least errors resulting from unintended default initializations will be
consistent and therefore more debuggable.<
> Seeing how abs(int.min) gives problems, and seeing how CPUs manage nans of FPs
efficiently enough, it can be nice for int.min to become the nan of integers (and
similar for short, long, and maybe tiny too). Such nan may also be useful for
purposes similar to nullable integers of C#.
> Bye,
> bearophile

This is IMHO (at least at first glance) a reasonable idea in the very long run.
However, it isn't practical here and now for D2, because NaN behavior is
implemented partly in hardware, and mathematically undefined integer operations
throw hardware exceptions instead of returning int.nan on current hardware.



More information about the Digitalmars-d mailing list