isinf
、isnan
函数,这些函数运行得很完美。但是在OS-X上它们不起作用,所以我决定使用std::isinf
和std::isnan
,这两个函数在Linux和OS-X上都能正常工作。但是Intel编译器不能识别它们,根据http://software.intel.com/en-us/forums/showthread.php?t=64188的说法,我猜测这是Intel编译器的一个bug。
现在,我只想避免麻烦,自己定义
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;
}