Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone/iPad double precision math

The accepted answer to this Community Wiki question: What are best practices that you use when writing Objective-C and Cocoa? says that iPhones can't do double precision math (or rather, they can, but only emulated in software.) Unfortunately the 2009 link it provides as a reference: Double vs float on the iPhone directly contradicts that statement. Both of these are old, being written when the 3GS was just coming out.

So what's the story with the latest arm7 architecture? Do I need to worry about the 'thumb' compiler flag the second link references? Can I safely use double variables? I am having nasty flashbacks to dark days of 386SXs and DXs and 'math coprocessors.' Tell me it's 2012 and we've moved on.

like image 898
Tim Avatar asked Jan 13 '12 16:01

Tim


1 Answers

In all of the iPhones, there is no reason double precision shouldn't be supported. They all use Cortex-A8 architecture with the cp15 coprocessor (which supports IEEE float and double calculations in hardware).

http://www.arm.com/products/processors/technologies/vector-floating-point.php

So yes, you can safely use doubles and it shouldn't be software emulated on the iPhones. Although this is done in hardware, it may still take more cycles to perform double mathemtic arithmatic vs single (float). In addition to using double, I would check to make sure the precision is appropriate for your application.

As a side note, if the processor supports NEON instruction set, doubles and floats may be calculated faster than using the coprocessor.

http://pandorawiki.org/Floating_Point_Optimization#Compiler_Support

EDIT: Though VFP and Neon are optional extensions to the ARM Core, most of the cortex-A8 have them and all of them ones used in the iPhone and iPad do as well.

like image 76
nmjohn Avatar answered Nov 08 '22 11:11

nmjohn