Here is the test program:
void testFunc()
{
double maxValue = DBL_MAX;
double slope = std::numeric_limits<double>::quiet_NaN();
std::cout << "slope is " << slope << std::endl;
std::cout << "maxThreshold is " << maxValue << std::endl;
std::cout << "the_min is " << std::min( slope, maxValue) << std::endl;
std::cout << "the_min is " << std::min( DBL_MAX, std::numeric_limits<double>::quiet_NaN()) << std::endl;
}
int main( int argc, char* argv[] )
{
testFunc();
return 0;
}
In Debug, I get:
slope is nan
maxThreshold is 1.79769e+308
the_min is nan
the_min is 1.79769e+308
In Release, I get:
slope is nan
maxThreshold is 1.79769e+308
the_min is 1.79769e+308
the_min is nan
Why would I get a different result in Release than Debug?
I already checked Stack Overflow post Use of min and max functions in C++, and it does not mention any Release/Debug differences.
I am using Visual Studio 2015.
std::min
, it's withstd::numeric_limits<double>::quiet_NaN()
– Consternationcl
having problems with correctNaN
handling in Release mode, but that was in VS 2008. I would hope they fixed it since then. – LarryNaN
will fit inLessThanComparable
– Kraken-frounding-math -fsignaling-nans
on the compiler so that it guarantees strict IEEE 754 compliance. That way it should never re-order comparisons (or any other optimisations) which might change behaviour due to NaN. For Visual Studio,/fp:precise
appears to be the equivalent (which promises not to optimise things such as x-x=0). – Deathful/fp:precise
is enabled by default and this does not prevent Debug behaviour to be different than Release... – Forelimb/fp:strict
, which may also be worth a shot (but potentially incurs a lot of overhead). – Deathful