Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 12, 2013, 08:15 PM   #1
dmatter
macrumors newbie
 
Join Date: Feb 2013
Problems with #include <math.h>

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!

Last edited by robbieduncan; Feb 13, 2013 at 10:04 AM. Reason: Improve title
dmatter is offline   0 Reply With Quote
Old Feb 12, 2013, 11:40 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by dmatter View Post
#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.
chown33 is offline   0 Reply With Quote
Old Feb 13, 2013, 12:58 AM   #3
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
Quote:
Originally Posted by chown33 View Post
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:
Code:
        #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
lee1210 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
3rd Grade Math: Summer Review Splash Math App klkatielong iPad Apps 0 Jul 18, 2012 12:56 PM
Problems with math Eeveelover Mac Programming 2 Jul 15, 2012 12:18 PM
[Math App] Homework teaches kids math and reports to parents Gaea deBomb iPhone and iPod touch Apps 0 Jul 3, 2012 04:35 AM
5+7+10+5+2+3= ? Math Aloud ! true mental math ... left & right brain. mobile.esd.mx iPhone and iPod touch Apps 0 Jun 1, 2012 04:17 PM

Forum Jump

All times are GMT -5. The time now is 06:31 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC