Re: [Pyobjc-dev] NSPoint/NSMakePoint oddness
Brought to you by:
ronaldoussoren
From: Adam A. <ad...@at...> - 2009-06-02 19:59:50
|
On 2 Jun 2009, at 14:44, Daniel Ashbrook wrote: > Is this expected behavior? > >>>> from Foundation import * >>>> NSMakePoint(100000100, 0) > <NSPoint x=100000096.0 y=0.0> > > Shouldn't I get out what I put in? > > dan I think it's to be expected, if unfortunate. NSPoint's components are CGFloat-valued (in 10.5 at least; in 10.4 and earlier, they're just 'float'), and I get the same result with this C code: > #include <ApplicationServices/ApplicationServices.h> > int main(int argc, const char *argv[]) { > CGFloat x; > x = 100000100; > printf("%f\n", x); > return 0; > } When building for 32-bit systems, CGFloat is defined as a C float, and for 64-bit, it's a double. I am indeed on a 32-bit system. The C code above works correctly (gives 100000100.000000) if I explicitly declare 'x' as double instead of CGFloat. Unfortunately, you can't change this for pre-compiled C/ObjC functions that will be expecting an NSPoint consisting of two 32-bit floats, so you'll have to work within this limitation. - Adam |