隐式转换将 64 位缩短为 32 位

发布于 2024-10-07 00:36:39 字数 116 浏览 0 评论 0原文

有人可以解释为什么这会导致标题中所述的错误吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沐歌 2024-10-14 00:36:39

fabs() 返回一个 double(64 位),但 CGFloat 被定义为一个 float(32 位) -少量)。它通常是无害的 - 我个人甚至会禁用编译器警告,因为使用 double 值执行计算通常至少与使用 float 一样快> 价值观。

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.

回忆凄美了谁 2024-10-14 00:36:39

更好的答案是使用#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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文