• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [OT] calling isnan
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] calling isnan


  • Subject: Re: [OT] calling isnan
  • From: Bill Northcott <email@hidden>
  • Date: Sat, 19 Feb 2005 12:27:32 +1100

On 19/02/2005, at 7:11 AM,Chris Espinosa <email@hidden> wrote:
I've run into a strange problem, and could use some advice.  I have a
C++ library that I'm porting from linux to Mac OS X.
...
The class makes
use
of the function isnan as part of the validation.  On Mac OS X, this
is a
....
However, when I compile the library, the linker says that this
function
is undefined.  I've tried including <architecture/ppc/math.h> directly
and still it doesn't work.  I've gone over the include file to see if
something special needs to be defined or undefined to get the macro.

isnan is a macro, so according to the linker, it is undefined. At some point in your project you are using isnan(x) without having an #include <math.h>. If the macro isn't defined at the point of use, the compiler assumes it's a function call, and the linker searches in vain for an implementation.

I spent some time going around this with the R people.

Basically the story is this:
isnan() is a C99 extension to standard C.
Standard C++ is based on an older standard of C.
Hence isnan() is not part of standard C++ and may or may not work.

The C++ equivalent of math.h is cmath. cmath on MacOS X and probably other platforms undefines isnan() and other C99 macros. Hence if your program includes cmath or one of the many headers such iostream that themselves include cmath then isnan() will not be available.

The code works on Linux because isnan() is a function not a macro.

The solution for any math library for C++ (such as libRmath) is to program your own isnan() like function that access the underlying system functions.

AFAIK the MacOS X C macro calls one of three underlying isnan() type functions according to the type of the variable (float,double,long double). To port your code just call the appropriate one of these directly. Of course the code needs to be in pre-processor conditionals. Alternatively, you could copy the existing macro into one of your headers with another name.

There was quite a long discussion of this on the main gcc mail list recently and think the Apple people implied the behaviour might change in future compiler releases. Presumably at some point the C99 macros or something equivalent will be in the standard C++.

Bill Northcott

PS this is not OT

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: [OT] calling isnan
      • From: Andreas Grosam <email@hidden>
    • Re: [OT] calling isnan
      • From: Jerry <email@hidden>
  • Prev by Date: Re: [OT] calling isnan
  • Next by Date: Trouble with saving Simplified Chinese (Mac OS) encoding
  • Previous by thread: Re: [OT] calling isnan
  • Next by thread: Re: [OT] calling isnan
  • Index(es):
    • Date
    • Thread