1

I'm getting a lot of headache with a simple isnan test in my code. I have a 3d vector class with variables x,y,z of type double, and the following function in the header file:

#ifdef WIN32
bool IsValid() const {return !_isnan(x) && _finite(x) && !_isnan(y) && _finite(y) && !_isnan(z) && _finite(z);} //is a valid vector? (funky windows _ versions...) 
#else
bool IsValid() const {return !isnan(x) && finite(x) && !isnan(y) && finite(y) && !isnan(z) && finite(z);} //is a valid vector? 
#endif    

I'm building in a Linux GCC environment on Eclipse CDT and getting the following error:

Function '__isnanl' could not be resolved

as well as

Function '__isnanf' could not be resolved

for all instances of isnan. Using std::isnan and including float.h and math.h don't solve it. Does anyone know what's going on?

Kevin
  • 53,822
  • 15
  • 101
  • 132
Nikita
  • 11
  • 3

2 Answers2

1

1) Try to include <math.h> 2) Write your own isnan(x) function

bool isnan(x)
{
   if (x==x)
   {
      return false;
   }
   else
   {
      return true;
   }
}

3) Could it be a silly naming problem?isnanl should probably be defined as isnan? See: Checking if a double (or float) is NaN in C++

Community
  • 1
  • 1
Mikhail
  • 7,749
  • 11
  • 62
  • 136
  • I've tried including math.h, it doesn't solve the problem either. I'm currently using the x==x hack, but I'd rather use the library function instead of the specification. A similar problem appeared under Windows with both _isnan and _finnite so it would be good to know how to fix it. Thanks! – Nikita Dec 14 '11 at 00:22
0

I run into the same issue. isnan() works on command-line but annoyingly, Eclipse reports it as an error. The problem is due to Eclipse CDT using the gcc compiler little differently. Looking a bit deeper, isnan() seems to be a macro that is translated to __isnan() or some other functions depending on some flags. Maybe these flags differ when you compile from Eclipse.

I fixed it by using function

__isnan(double x)

which can also be found on math.h, works correctly on cmdline compiler and Eclipse does not complain about it.

Hannes R.
  • 1,379
  • 16
  • 23