有什么理由这不是冗余代码吗?

发布于 2024-09-05 15:14:22 字数 226 浏览 4 评论 0原文

我在一些现有的代码库中遇到了这段代码:

double rad = ComputeCurviness();
double off = Math.Abs(rad);
if (rad < 0) off = -off;

它似乎基本上只是使 off 等于 rad。这些变量稍后在代码中可以互换使用。有什么理由保留此代码吗?

I came across this code in some existing codebase:

double rad = ComputeCurviness();
double off = Math.Abs(rad);
if (rad < 0) off = -off;

It seems to be basically just making off equal to rad. The variables are used interchangeably later in the code. Is there any reason to leave this code in?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

倾城花音 2024-09-12 15:14:22

如果rad为-0.0,off将为+0.0。您必须检查代码,看看这是否真的会产生影响。两者在计算和比较方面是等价的,但-0.0是负数,只要你足够努力就能发现。

If rad is -0.0, off will be +0.0. You'd have to inspect the code to see whether this would actually make a difference. The two are equivalent when it comes to calculations and comparisons, but -0.0 is negative, which you can detect if you try hard enough.

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