Note that there are some explanatory texts on larger screens.

plurals
  1. POReplacement for `fabs`, `fmax`, etc. for use with CGFloat on 64-bit iOS devices
    text
    copied!<h2>Question</h2> <p>Consider layout code like this:</p> <pre><code>CGFloat descriptionHeight = // height of a paragraph of text with zero or more words; CGFloat imageHeight = // height of an image; CGFloat yCoordinateOfSomeOtherView = fmax(descriptionHeight, imageHeight) + 5.0f; </code></pre> <p>How should the third line be rewritten with support for 64-bit iOS devices?</p> <p>(The current code doesn't take into account whether <code>yCoordinateOfSomeOtherView</code> is a <code>float</code> or a <code>double</code>.)</p> <h2>Options</h2> <p>A few options (I'm not sure which is best):</p> <h3>1. Define my own macro</h3> <pre><code>#if defined(__LP64__) &amp;&amp; __LP64__ #define cgfmax(x,y) fmaxf(x,y) #else #define cgfmax(x,y) fmax(x,y) #endif </code></pre> <p>I could then replace <code>fmax</code> with <code>cgfmax</code>.</p> <h3>2. Use <code>tgmath.h</code></h3> <p><a href="https://stackoverflow.com/a/5352779/1445366">This Stack Overflow answer</a> from 2011 suggests replacing <code>math.h</code> with <code>tgmath.h</code>. This replaces the implementation of <code>fmax</code> with one that calls <code>__typeof__</code> on each argument and returns either <code>fmax</code> or <code>fmaxf</code> depending on the argument types.</p> <h3>3. Ignore this issue</h3> <p>Since CGFloats relate to layout, the data loss potentially incurred storing a <code>float</code> into a <code>double</code> will usually be insignificant. That is, they'll represent tiny fractions of pixels. </p> <h2>Summary</h2> <p>I'm looking for any other options or helpful advice from someone who's done a 32-bit to 64-bit transition before.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload