开发者

implicit conversion shortens 64 bit to 32 bit

开发者 https://www.devze.com 2023-01-29 12:05 出处:网络
Can someone expl开发者_开发知识库ain why this causes the error stated in the title? CGFloat dx = fabs(lastPoint.x - currentPoint.x);

Can someone expl开发者_开发知识库ain 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消