我一直在使用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