title: CGFloat-based math functions?
body: <p>In both OS X and iOS, Apple is using the CGFloat typedef to automatically get a <code>float</code> on 32-bit systems and a <code>double</code> on 64-bit systems. But when using the normal Unix math functions you need to make that decision on a case by case basis. </p>
  
  <p>For example the <code>floor()</code> function is defined as:</p>
  
  <p><code>double floor(double x);</code></p>
  
  <p>and the <code>floorf()</code> function is defines as:</p>
  
  <p><code>float floorf(float x);</code></p>
  
  <p>I know all iOS devices are 32-bit <em>today</em>, but the reason to use CGFloat is to automatically get improved precision when the first 64-bit iOS devices are introduced (iPad 5?) and not having to change any code. But to make that possible we need CGFloat-based math functions:</p>
  
  <p><code>CGFloat Floor(CGFloat x);</code></p>
  
  <p>Are there any functions like that in iOS or any third-party libraries? Or how do other developers handle this? I suspect most are either using <code>CGFloat</code> together with the <code>float</code>-versions on iOS but then you would "need" to change every line with a math function if compiling for a 64-bit iOS device (and handle two different versions of of your code base).</p>
  
  <p>Or you could just use <code>float</code> instead of <code>CGFloat</code> everywhere and not worrying about 64-bit iOS. But then you would get inconsistency with Apple's libraries and IMHO uglier code.</p>
  
  <p>Or you could maybe use <code>CGFloat</code> together with the <code>double</code>-versions and just take the space and performance hit of letting the compiler convert between double and float all the time. And not caring about possible "Implicit conversion to 32 Bit Type" warnings. </p>
  
  <p>Or maybe the best strategy, bet on no 64-bit version of iOS will ever arrive (or at least in a near enough future) and use <code>CGFloat</code> together with <code>float</code>-versions of the Unix math functions and not worrying about the future.</p>
  
  <p>What strategy are you using?</p>