I know CGFloat is double on 64-bit devices and float on 32-bit devices. However, my understanding is that ARM 64-bit only refers to integers and pointers. The Floating point unit has been capable of handling doubles long before iOS devices went 64-bit. The floating point unit can operate on 4 32-bit floats at once, or 2 doubles or one 128-bit float. So, if you use doubles instead of floats you are (theoretically) halfing the processing power.
Is this correct?
I haven't been able to get much detailed information on Apple's implementation of the ARM floating point processor, so I might have got some of the details wrong. Please, feel free to correct 😉
Well, what I really want to know is if you gain anything from using floats instead of doubles on iOS devices.
Hmmm. I was hoping for a more in-depth description of your overall problem. For example:
How many numbers are you working with?
How do they flow in and out of memory? And in and out of the CPU?
When you operate on those numbers, how many are you operating on in parallel? And how complex are those mathematical operations?
Are their any GPU entanglements?
The most obvious difference between floats and doubles is their actual size in memory. If you’re working with a large array of numbers, the float version will be half the size of the double version, which is clearly a good thing. Moreover, if you’re doing simple operations on large arrays of numbers, it’s likely that those operations will be memory bound, in which case you’ll get twice the throughput with floats.
OTOH, if you’re doing simple day-to-day arithmetic—calculating the value for a progress bar, say—it’s generally OK to just default to using a double.
Share and Enjoy
—
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"