这是测试程序:
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;
}
在调试中,我得到:
slope is nan
maxThreshold is 1.79769e+308
the_min is nan
the_min is 1.79769e+308
在发布中,我得到:
slope is nan
maxThreshold is 1.79769e+308
the_min is 1.79769e+308
the_min is nan
为什么我会在 Release 中得到与 Debug 不同的结果?
我已经检查了 Stack Overflow post Use of min and max functions in C++,它没有提到任何发布/调试差异。
我正在使用 Visual Studio 2015。