Re: CGFloat and 64 Bit
Re: CGFloat and 64 Bit
- Subject: Re: CGFloat and 64 Bit
- From: Michael Ash <email@hidden>
- Date: Mon, 9 Feb 2009 20:30:32 -0500
On Mon, Feb 9, 2009 at 2:02 PM, Nick Zitzmann <email@hidden> wrote:
>
> On Feb 9, 2009, at 11:04 AM, Sean McBride wrote:
>
>> I agree with the OP that CGFloat is very annoying in this respect. My
>> solution has been to use the 'f' suffix for constants.
>
> The problem with that is, if you do a mathematical operation on a double
> using a float (including constants), you will lose a little precision, which
> does not happen when you stick strictly to doubles. If losing precision is
> not important, though, then I guess that's OK.
Not really sure what you mean by this. It's true that a constant such
as 11.2f is a less precise representation of 11.2 than the non-float
version. But aside from actually defining the constants (and note that
all exact integers under 2^23 and many common fractional values will
be *exactly* represented and thus suffer no precision loss) there's no
trouble to be had. If you perform an operation on a double and a
float, the float gets promoted before the operation is carried out.
Writing aDouble + 11.0f gives the same result as writing aDouble +
11.0. Writing aDouble + 11.2f gives a slightly different result from
aDouble + 11.2, but only because the constant itself holds a different
value. The calculation itself is just as precise in both cases.
If you're dealing with Cocoa graphics, worrying about the precision
being lost because you're using floats instead of doubles is somewhat
foolhardy. Nothing is going to visually change because your NSSize
constants only have 7 digits of precision instead of 14. If they do,
then you can't run in 32-bit mode anyway, and so this problem goes
away since you'll only be compiling for 64-bit.
Mike
_______________________________________________
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