Given this code sample:
CGFloat a = 1;
CGFloat b = 2;
CGFloat c = fabsf(a-b);
The current Xcode beta compiler gives me this warning:
Absolute value function 'fabsf' given an argument of type 'double' but has parameter of type 'float' which may cause truncation of value
Why?
You can use fabs
instead of fabsf
.
Link
I see, the code works with a plain float
type. And when I hunted for the definition of CGFloat
, I found this:
#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
typedef CGFLOAT_TYPE CGFloat;
So CGFloat
is now actually a double
, hence the warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With