문제

Can someone explain why this causes the error stated in the title?

CGFloat dx = fabs(lastPoint.x - currentPoint.x);

Thanks

도움이 되었습니까?

해결책

fabs() returns a double (64-bit), but CGFloat is defined to be a float (32-bit). It's generally harmless – I personally would even disable the compiler warning, as performing calculations using double values is typically at least as fast as using float values.

다른 팁

A better answer is to use #include <tgmath.h>. That header defines "adaptive" functions that call the correct function on whichever parameter size.

With that header included, you can simply call fabs without getting that warning (nor worrying about loss of precision caused by the use of the wrong function).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top