Re: Math.h functions with CGFloat
Re: Math.h functions with CGFloat
- Subject: Re: Math.h functions with CGFloat
- From: James Montgomerie <email@hidden>
- Date: Tue, 10 Aug 2010 15:12:58 +0100
You should, I believe, be able to include <tgmath.h> ('type generic math' - a C99 addition) instead, and then just 'use' the non-suffixed versions of the functions. Hidden macro magic is supposed to then make the compiler call the double or float versions as appropriate for the type used.
Having said that, I had a lot of trouble when trying this in my iPhone app a year or so ago. Things seemed very slow when complied, and disassembly showed all sorts of float<->double conversion going on. I ended up explicitly calling the f-suffixed ones anyway. I don't think I should have needed to though, and if there was a bug back then (rather than just me doing something incorrect) it could be fixed now.
Jamie.
On 10 Aug 2010, at 15:04, steven Hooley wrote:
> Sorry, 'safe' was a bad choice. I do care because i have compiler
> warnings. I have started defining macros for each function and thought
> i better check that they didn't already exist.
> Thankyou
>
> On 10 August 2010 14:54, Alastair Houghton <email@hidden> wrote:
>> On 10 Aug 2010, at 13:42, steven Hooley wrote:
>>
>>> Is there a preferred way to use the Math.h functions with CGFloats
>>> that is 32 and 64 bit safe?
>>
>> Why would they be unsafe? (They aren't.)
>>
>> It's possible that using the double versions (the ones without the "f" suffix) is inefficient in 32-bit mode, but in practice you're very unlikely to notice. If you particularly cared, you could #define some macros for them, but I doubt it's worthwhile unless you're going to do some heavy-duty geometry (and in that case, you might find that you want to use double anyway, for accuracy).
>>
>> BTW, <math.h> isn't capitalised; please don't use random upper-case letters when including header files... it causes grief if your source code is ever moved somewhere case-sensitive.
>>
>>> Should i even be using Math.h functions in Cocoa?
>>
>> Why should you not?
>>
>> Kind regards,
>>
>> Alastair.
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden