Order of float declaration changes NaN throwing behavior
Andrej Mitrovic
andrej.mitrovich at gmail.com
Mon Jul 11 09:45:01 PDT 2011
import std.math;
void main()
{
float foo;
FloatingPointControl fpc;
fpc.enableExceptions(FloatingPointControl.allExceptions);
//~ float foo; // put it here instead and it throws
auto x = foo / 0;
}
If you compile and run this, nothing is thrown. If you comment out the
first declaration of foo and replace it with the second one, then it
throws. This looks like a bug to me.
This only seems to affect NaNs. Declaaration order does not seem to
affect other invalid operations, for example:
import std.math;
void main()
{
float foo = 0.0f;
FloatingPointControl fpc;
fpc.enableExceptions(FloatingPointControl.allExceptions);
auto x = foo / 0; // throws, as it should
}
And disabling exceptions also works regardless of declaration order:
import std.math;
void main()
{
float foo = 0.0f;
FloatingPointControl fpc;
fpc.disableExceptions(FloatingPointControl.allExceptions); //
note: disableExceptions
auto x = foo / 0; // nothing thrown, good because we've disabled
all exceptions
}
So it only seems to affect NaNs.
More information about the Digitalmars-d-learn
mailing list