Page 1 of 1

using floats with macosx

Posted: Sat Jan 14, 2012 8:32 pm
by diegor
I want to use the same precision (float) in both my ios and macosx builds of my code. The problem is that the macros in chipmunk_types.h read:

#if defined(__LP64__) && __LP64__
#define CP_USE_DOUBLES 1
#else
#define CP_USE_DOUBLES 0
#endif

Should the code be changed so those lines are ignored if CP_USE_DOUBLES have been already defined?

Thanks!

Re: using floats with macosx

Posted: Sat Jan 14, 2012 10:07 pm
by slembcke
It doesn't look like this? What version are you using?

Code: Select all

#ifdef CP_USE_CGPOINTS
	#if TARGET_OS_IPHONE
		#import <CoreGraphics/CGGeometry.h>
	#elif TARGET_OS_MAC
		#import <ApplicationServices/ApplicationServices.h>
	#endif
	
	#if defined(__LP64__) && __LP64__
		#define CP_USE_DOUBLES 1
	#else
		#define CP_USE_DOUBLES 0
	#endif
#endif
I thought I changed it to look like that a long time ago.

So it's a little wonky, but you have to set both CP_USE_CGPOINTS to be 0 and CP_USE_DOUBLES to be 0.

Also, why care which floating point precision? Using the same precision won't make the floating point math be the same between different CPUs or compilers. The only thing it does marginally help with is if you are accessing the memory directly like doing binary serialization or vertex arrays for GL or something.

Re: using floats with macosx

Posted: Sun Jan 15, 2012 9:02 pm
by diegor
The problem is that in my case I want to use floats and also CGPoints, that's why I was suggesting the change above, which should be harmless to existing code.

Thanks again for your help!

Re: using floats with macosx

Posted: Sun Jan 15, 2012 9:48 pm
by slembcke
CGFloats (and therefore CGPoints) are defined differently depending on if you are no a 32 or 64 bit system. That's why I have the 64bit check in the typedef.