4 ms·
The case that has bugged me is when I have some integer number of items and I need to compute some CGFloat for drawing something based on it. count * SpacingPix
by webjprgm 11y ago
The case that has bugged me is when I have some integer number of items and I need to compute some CGFloat for drawing something based on it. count * SpacingPixels gives an error, need CGFloat(count) * SpacingPixels even though there is no possibility of losing precision by the up-cast from Int to CGFloat.
It is also slightly annoying to have Double and CGFloat not be the same, but I solved that by just always using CGFloat pretty much everywhere even when not referring to pixels or points.
I don't think I would overload + and *, though, due to possible complications with the error messages as the article suggests. But I might play with more terse Ruby-like ".to_f" as an extension or something ...
- Alphasite_ 11y agoCGFloat is a different type based on the system, is it not?
- _jsn 11y agoYes. It's double precision on 64-bit platforms and single precision on 32-bit. #if defined(__LP64__) && __LP64__ # define CGFLOAT_TYPE double # define CGFLOAT_IS_DOUBLE 1 # define CGFLOAT_MIN DBL_MIN # define CGFLOAT_MAX DBL_MAX #else # define CGFLOAT_TYPE float # define CGFLOAT_IS_DOUBLE 0 # define CGFLOAT_MIN FLT_MIN # define CGFLOAT_MAX FLT_MAX #endif
- nadohs 11y agoExactly, this is also pointed out in the struct definition in CoreGraphics for CGFloat. /// The native type used to store the CGFloat, which is Float on 32-bit architectures and Double on 64-bit architectures.