NaNs Just Don't Get No Respect

renoX renozyx at gmail.com
Tue Aug 21 01:14:33 PDT 2012


On Monday, 20 August 2012 at 19:28:33 UTC, Peter Alexander wrote:
[cut]
> 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!


In theory, one could prevent this by setting the floating point 
control word to trigger a trap when reading a NaN which I think 
*should* be the default.

Unfortunately it doesn't seem to work, there is an FPE in the 
code below, where it shouldn't.
Then again, the online compiler I've tried is very old: dmd-2.042.

>>
import std.stdio, std.math, std.algorithm;

int main()
{
FloatingPointControl fpc;
fpc.enableExceptions(FloatingPointControl.severeExceptions);

float x = 0.0f;
float y; // oops
y=1;
float z = min(x, y);

writeln("min x,y=",z);

return 0;
}
<<








More information about the Digitalmars-d-announce mailing list