我一直在使用isinf
,isnan
函数在Linux平台上工作完美。 但是这在OS-X上不起作用,所以我决定使用std::isinf
std::isnan
,它可以在Linux和OS-X上运行。我该如何制作一个便携式isnan/isinf函数
但英特尔编译器无法识别它,我根据http://software.intel.com/en-us/forums/showthread.php?t=64188
猜测其错误在英特尔编译器现在我只是想避免麻烦和定义自己的isinf
,isnan
实施。
有谁知道这可以做到吗?
编辑:
我结束了在我的源代码做这做isinf
/isnan
工作
#include <iostream>
#include <cmath>
#ifdef __INTEL_COMPILER
#include <mathimf.h>
#endif
int isnan_local(double x) {
#ifdef __INTEL_COMPILER
return isnan(x);
#else
return std::isnan(x);
#endif
}
int isinf_local(double x) {
#ifdef __INTEL_COMPILER
return isinf(x);
#else
return std::isinf(x);
#endif
}
int myChk(double a){
std::cerr<<"val is: "<<a <<"\t";
if(isnan_local(a))
std::cerr<<"program says isnan";
if(isinf_local(a))
std::cerr<<"program says isinf";
std::cerr<<"\n";
return 0;
}
int main(){
double a = 0;
myChk(a);
myChk(log(a));
myChk(-log(a));
myChk(0/log(a));
myChk(log(a)/log(a));
return 0;
}
密切相关:[如果使用双__Checking(或浮动)为NaN在C++ __](HTTP://计算器。 com/questions/570669/checking-if-a-double-or-float-is-nan-in-c) – bobobobo