我怎么做一个便携式isnan / isinf功能 [英] how do I make a portable isnan/isinf function

查看:551
本文介绍了我怎么做一个便携式isnan / isinf功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 isinf ,其上完美地工作Linux平台 isnan 功能。
但这并没有在OS-X的工作,所以我决定用的std :: isinf 的std :: isnan 这适用于Linux和OS-X。

不过,英特尔编译器不能识别它,我按照<猜测其错误在英特尔编译器href=\"http://software.intel.com/en-us/forums/showthread.php?t=64188\">http://software.intel.com/en-us/forums/showthread.php?t=64188

所以,现在我只是想避免麻烦和定义自己的 isinf isnan 实施

有谁知道怎么可以这样做?

编辑:

我结束了在我的源代码code做这做 isinf / isnan 工作

 的#include&LT;&iostream的GT;
#包括LT&;&CMATH GT;#IFDEF __INTEL_COMPILER
#包括LT&;&mathimf.h GT;
#万一诠释isnan_local(双X){
#IFDEF __INTEL_COMPILER
  返回isnan(X);
#其他
  返回的std :: isnan(X);
#万一
}INT isinf_local(双X){
#IFDEF __INTEL_COMPILER
  返回isinf(X);
#其他
  返回的std :: isinf(X);
#万一
}
INT myChk(双A){
  的std :: CERR&LT;&LT;val为:&LT;&LT; A&LT;&LT;\\ t的;
  如果(isnan_local(a))的
    的std :: CERR&LT;&LT;节目说isnan
  如果(isinf_local(a))的
    的std :: CERR&LT;&LT;节目说isinf
  的std :: CERR&LT;&LT;\\ n;
  返回0;
}诠释主(){
  双一= 0;
  myChk(一);
  myChk(日志(一));
  myChk(-log(一));
  myChk(0 /日志(一));
  myChk(日志(一)/日志(一));  返回0;
}


解决方案

您也可以使用升压此任务:

 的#include&LT;升压/数学/ special_functions / fpclassify.hpp&GT; // isnan如果(::提高::数学isnan(...)....)

I've been using isinf, isnan functions on Linux platforms which worked perfectly. But this didn't work on OS-X, so I decided to use std::isinf std::isnan which works on both Linux and OS-X.

But the Intel compiler doesn't recognize it, and I guess its a bug in the intel compiler according to http://software.intel.com/en-us/forums/showthread.php?t=64188

So now I just want to avoid the hassle and define my own isinf, isnan implementation.

Does anyone know how this could be done?

edit:

I ended up doing this in my source code for making isinf/isnan working

#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;
}

解决方案

You could also use boost for this task:

#include <boost/math/special_functions/fpclassify.hpp> // isnan

if( boost::math::isnan( ... ) .... )

这篇关于我怎么做一个便携式isnan / isinf功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆