Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cmath and math.h Changes in Xcode 2.4 (Mike Jackson)



On 30/08/2006, at 8:12 AM, Mike Jackson wrote:

Looking around it seems the "safer" way to do this is to use the
#define isnan(x) std::isnan(x)

.... stuff removed

As I am learning quickly, there is no "standard" in C++ so everyone does it
differently. So OpenSceneGraph will have to do it one way and ITK will have
to do it another way..

There are perfectly good standards for C++. There are also a lot of people who don't read them.


isnan() is not in those standards and it should not be in std::, which is why a properly constructed cmath header strips it out of math.h. Linux does not, which is why you find these problems in Linux originated code.

The 'right way' is not to use std::isnan() in C++ code. You should certainly not muck about with the headers because that only works on a system like Linux where isnan() is a function. On Darwin/MacOS X and many other systems, isnan() is a macro which translates to different functions depending on the type of the argument.

The work around if you want isnan() functionality in C++ code is to write a little C function say myisnan() which calls isnan(), then use myisnan() in your C++ code. Since myisnan() will be a function not a macro it will all work for you.

For fuller discussions of this issue see the R-devel list. For other examples look at the sources of any C++ opensource mathematical/ statistical class library.

As you will see on the R-devel list, it took some time for the R developers to accept that this was right, but they did in the end.

Best of luck
Bill Northcott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.