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

后端 未结 2 710
挽巷
挽巷 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 11:04

    You may use those functions from tgmath.h.

    #include 
    
    ...
    
    double d = 1.5;
    double e = floor(d);   // will choose the 64-bit version of 'floor'
    
    float f = 1.5f;
    float g = floor(f);    // will choose the 32-bit version of 'floorf'.
    

提交回复
热议问题