Question
Consider layout code like this:
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;
How should the third line be rewritten with support for 64-bit iOS devices?
(The current code doesn't take into account whether yCoordinateOfSomeOtherView
is a float
or a double
.)
Options
A few options (I'm not sure which is best):
1. Define my own macro
#if defined(__LP64__) && __LP64__
#define cgfmax(x,y) fmaxf(x,y)
#else
#define cgfmax(x,y) fmax(x,y)
#endif
I could then replace fmax
with cgfmax
.
2. Use tgmath.h
This Stack Overflow answer from 2011 suggests replacing math.h
with tgmath.h
. This replaces the implementation of fmax
with one that calls __typeof__
on each argument and returns either fmax
or fmaxf
depending on the argument types.
3. Ignore this issue
Since CGFloats relate to layout, the data loss potentially incurred storing a float
into a double
will usually be insignificant. That is, they'll represent tiny fractions of pixels.
Summary
I'm looking for any other options or helpful advice from someone who's done a 32-bit to 64-bit transition before.