• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CGFloat and 64 Bit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CGFloat and 64 Bit


  • Subject: Re: CGFloat and 64 Bit
  • From: Steve Sisak <email@hidden>
  • Date: Mon, 9 Feb 2009 14:11:02 -0500

At 12:41 PM -0500 2/9/09, Michael Ash wrote:
> A very bad idea as it would force usage of float in 64bits applications
where NSSize expect 64 bits CGFloat.

So? Float converts to double just fine. There are no bad consequences for passing 11.2f to a function that takes double, aside from an utterly negligible loss of precision when representing the fractional part.

It depends if you care about that precision.

Remember that base 10 is not precisely represented in base 2.

Here's a test program for you:

int main (int argc, const char * argv[])
{
    double d1 = 11.2;
    double d2 = 11.2f;

    printf("d1 = %.15f, d2 = %.15f\n", d1, d2);

    return 0;
}


Produces:

d1 = 11.199999999999999, d2 = 11.199999809265137

(On a 1st gen Core Duo MacBook Pro running 10.5.6, YMMV)

The "right thing" would be for the compiler to use the same precision as the type being assigned to if no explicit precision was supplied but, for whatever reason, that's not what the standard says.

Floating point is tricky to get right.

-Steve
_______________________________________________

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


References: 
 >CGFloat and 64 Bit (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: CGFloat and 64 Bit (From: Rob Keniger <email@hidden>)
 >Re: CGFloat and 64 Bit (From: Jean-Daniel Dupas <email@hidden>)
 >Re: CGFloat and 64 Bit (From: Michael Ash <email@hidden>)

  • Prev by Date: Re: CGFloat and 64 Bit
  • Next by Date: Re: Determining if a user is logged in from a Launchd Daemon
  • Previous by thread: Re: CGFloat and 64 Bit
  • Next by thread: Re: CGFloat and 64 Bit
  • Index(es):
    • Date
    • Thread