CGFloat: round, floor, abs, and 32/64 bit precision

后端 未结 2 705
挽巷
挽巷 2021-01-04 10:16

TLDR: How do I call standard floating point code in a way that compiles both 32 and 64 bit CGFloats without warnings?


CGFloat is defined as either double or fl

2条回答
  •  长发绾君心
    2021-01-04 10:55

    If you only need a few functions you can use this instead:

    #if CGFLOAT_IS_DOUBLE
    #define roundCGFloat(x) round(x)
    #define floorCGFloat(x) floor(x)
    #define ceilCGFloat(x) ceil(x)
    #else
    #define roundCGFloat(x) roundf(x)
    #define floorCGFloat(x) floorf(x)
    #define ceilCGFloat(x) ceilf(x)
    #endif
    

提交回复
热议问题