NaNs Just Don't Get No Respect

Peter Alexander peter.alexander.au at gmail.com
Mon Aug 20 12:28:32 PDT 2012


On Sunday, 19 August 2012 at 22:22:28 UTC, Walter Bright wrote:
> > I find it more likely that the NaN will go unnoticed and
> > cause rare bugs.
>
> NaNs in your output are pretty obvious. For example, if your 
> accounting program prints "NAN" for the amount on the payroll 
> cheques, someone is guaranteed to notice. But if it's a few 
> cents off in your disfavor, it might take you years to discover 
> there's a problem.
>
> Critical systems also would find a NaN command a lot easier to 
> detect than an off-by-two command, and would be able to shut 
> down and engage the backup.

The problem is that it's easy for even NaN's to be filtered out.

float x = 0.0f;
float y; // oops
float z = min(x, y); // NaN has disappeared, unnoticed!

My argument is that conservative compile time errors on 
uninitialised variables are more likely to catch these errors.


More information about the Digitalmars-d-announce mailing list