Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
939
41
Tokyo, Japan
Before development for iPhone/iPad, It is said as possible as not use float number for calculation, but I found all sample source for iPhone/iPad use float all time.

For example, when create a view using CGRectMake(0.0, 0.0, 123.0, 824.0) or CGRectMake(0.0f, 0.0f, 123.0f, 824.0f), maybe I am a newbie, I still like to use CGRectMake(0, 0, 123, 824), I have two questions:

1. Do those methods above return the same result?

2. Why the float is So fast in iPhone/iPad or Mac?

Sorry for very basic and general questions:confused:
 
1. The compiler can promote the integer values to floats without losing precision so it will silently do so.

2. The ARM CPU does floating point numbers in hardware, as do most modern CPU's.
 
CGRectMake's parameters are defined as floats, so whether you say 123.0 or 123.0f or 123 when you call the function, the numbers will be stored in and operated on in floating point format.

Floating point operations are fast on any modern CPU, but integer operations are always likely to be even faster. Of course there are some cases where you just can't use integers, so floats are used instead. Unless you are doing floating point math in long, tight loops, you are unlikely to notice that float processing is slower than integer processing.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.