On Mon, Feb 9, 2009 at 11:11 AM, Steve Sisak <[email protected]> wrote: > 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.
This is because expressions are self-contained. The (11.2) on the right hand side of the equals sign is a complete expression unto itself, it's type and value cannot depend on anything outside of said expression, (11.2) means the exact same thing, anywhere it is used; (11.2) is *always* a double with a value as close to 11.2 as possible, just as (42) is *always* an int with the value 42. (11.2) will never be a float, and 42 will never be a char, short, long, or anything else. This is pretty core to the C and C++ type systems. To allow the type of the expression to change depending on what was being done with it (i.e. if it's being used to initialize a double vs. a float) would needlessly complicate the languages. -- Clark S. Cox III [email protected] _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
