隐式转换将 64 位缩短为 32 位
有人可以解释为什么这会导致标题中所述的错误吗?
CGFloat dx = fabs(lastPoint.x - currentPoint.x);
谢谢
Can someone explain why this causes the error stated in the title?
CGFloat dx = fabs(lastPoint.x - currentPoint.x);
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
fabs()
返回一个double
(64 位),但CGFloat
被定义为一个float
(32 位) -少量)。它通常是无害的 - 我个人甚至会禁用编译器警告,因为使用double
值执行计算通常至少与使用float
一样快> 价值观。fabs()
returns adouble
(64-bit), butCGFloat
is defined to be afloat
(32-bit). It's generally harmless – I personally would even disable the compiler warning, as performing calculations usingdouble
values is typically at least as fast as usingfloat
values.更好的答案是使用
#include
。该标头定义了“自适应”函数,可以根据任何参数大小调用正确的函数。包含该标头后,您可以简单地调用 fabs,而不会收到该警告(也不用担心由于使用错误函数而导致精度损失)。
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).