9

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.

Community
  • 1
  • 1
Tim
  • 5,024
  • 2
  • 30
  • 58

1 Answers1

6

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.

nmjohn
  • 1,432
  • 7
  • 16
  • Alright, thanks. That's what I thought it must be. Application domain is audio DSP; hence my desire for doubles. I was surprised to find those two authoritative, high-scoring answers on SO with such self-contradictory information. Leaving open in case anyone can comment on the 'Thumb' flag. – Tim Jan 13 '12 at 20:22
  • You don't need to worry about the Thumb compiler flag, unless you're writing low level assembly, this will be all optimized based on your optimization level and whether you want it optimized for time or space. – nmjohn Jan 13 '12 at 20:28
  • Thanks. I thought this would all prove to be a non-issue. – Tim Jan 13 '12 at 20:46
  • NEON is single-precision only (mentioned in the 2nd link you provided) – borrrden Jun 27 '12 at 07:19