PDA

View Full Version : Problems with #include <math.h>




dmatter
Feb 12, 2013, 08:15 PM
I have a problem which sounds similar.
My code looks roughly like this:

.
.
#include <math.h>
.
.
uint8_t test;
isnan(test);
.

The error I get is "No matching function call to isnan".
For more context, the reason I'm chasing this down is because I'm using the PCL library and Xcode is giving me compile errors which seem to have this as their root cause.

I've tried adding the "Foundations" framework, which someone suggested somewhere, but that didn't help.
I've tried adding "/usr/bin/gcc" to my header search paths, but that hasn't worked either.

Any ideas or suggestions would be great.

Thanks!



chown33
Feb 12, 2013, 11:40 PM
#include <math.h>
.
.
uint8_t test;
isnan(test);
.

The error I get is "No matching function call to isnan".

Even after this code compiles, it's still wrong.

First, the type of 'test' is uint8_t. That's not a floating-point type, so no NaN is possible. Any value that 'test' can possibly have is guaranteed to never be a NaN.

Second, isnan() returns a value. In the code shown, the return value of the function is neither tested nor assigned. It's just being ignored.

lee1210
Feb 13, 2013, 12:58 AM
Even after this code compiles, it's still wrong.

First, the type of 'test' is uint8_t. That's not a floating-point type, so no NaN is possible. Any value that 'test' can possibly have is guaranteed to never be a NaN.

Second, isnan() returns a value. In the code shown, the return value of the function is neither tested nor assigned. It's just being ignored.

Yes, this. What I said probably isn't as important or relevant. Sorry about that.

Also, if you're having trouble compiling a specific library, there's likely discussions about that on the site you got the source from, or instructions.

For kicks, in math.h:
#define isnan(x) \
( sizeof (x) == sizeof(float ) ? __inline_isnanf((float)(x)) \
: sizeof (x) == sizeof(double) ? __inline_isnand((double)(x)) \
: __inline_isnan ((long double)(x)))
...
static __inline__ int __inline_isnanf (float ) __MATH_H_ALWAYS_INLINE__;
static __inline__ int __inline_isnand (double ) __MATH_H_ALWAYS_INLINE__;
static __inline__ int __inline_isnan (long double) __MATH_H_ALWAYS_INLINE__;
...
static __inline__ int __inline_isnanf( float __x ) { return __x != __x; }
static __inline__ int __inline_isnand( double __x ) { return __x != __x; }
static __inline__ int __inline_isnan( long double __x ) { return __x != __x; }


Doing things the C way would end up with the long double version being used, which wouldn't go well. I was trying to look at the CPP versions, and it looks like there is some templating going on. I'm not positive if, eventually, this template leads to the macros. I'm not as hot with C++, so it wasn't quite as straight-forward.

If you actually try testing a floating-point value, though, you're much more likely to get things going, as chown33 said.

-Lee