The absolute value function "fabsf" is given by an argument of type "double", but has a parameter of type "float", which can cause truncation of the value?

Given this code example:

CGFloat a = 1; CGFloat b = 2; CGFloat c = fabsf(ab); 

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?

+7
objective-c xcode
source share
2 answers

I see the code works with a simple float type. And when I was hunting 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 now actually double , so a warning.

+7
source share

You can use fabs instead of fabsf .

Link

+13
source share

All Articles