我-Ofast
在我的程序中使用 gcc 选项会导致延迟要求。我写了简单的测试程序:
#include <iostream>
#include <math.h>
static double quiet_NaN = std::numeric_limits<double>::quiet_NaN();
int main()
{
double newValue = 130000;
double curValue = quiet_NaN;
printf("newValue = %f\n", newValue);
printf("curValue = %f\n", curValue);
printf("isnan(newValue) = %d\n", isnan(newValue));
printf("isnan(curValue) = %d\n", isnan(curValue));
printf("newValue == curValue %d\n", (newValue == curValue));
printf("newValue != curValue %d\n", (newValue != curValue));
}
我尝试使用默认标志和 -Ofast 运行它:
$ g++ TestPointer.cpp
$./a.out
newValue = 130000.000000
curValue = nan
isnan(newValue) = 0
isnan(curValue) = 1
newValue == curValue 0
newValue != curValue 1
$ g++ -Ofast TestPointer.cpp
$ ./a.out
newValue = 130000.000000
curValue = nan
isnan(newValue) = 0
isnan(curValue) = 1
newValue == curValue 1
newValue != curValue 0
所以结果!=
并不==
能被信任。这是否意味着我应该==
且!=
仅当两个值都不是 nan 时,否则我应该在isnan
之前进行测试?
是否保证isnan
可以正常工作-Ofast
?double with 的正确性==
和!=
工作方式如何-Ofast
?有人可以提供由添加的限制的完整列表-Ofast
吗?