加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 为什么anyValue%1“愚蠢数学”在声纳中anyValue是双倍

发布时间:2020-12-14 05:10:44 所属栏目:Java 来源:网络整理
导读:SonarQube在我的代码中引发了主要的违规 Silly math should not be performed.说明说 Certain math operations are just silly and should not be performed because their results are predictable. In particular, anyValue % 1 is silly because it will
SonarQube在我的代码中引发了主要的违规 Silly math should not be performed.说明说

Certain math operations are just silly and should not be performed
because their results are predictable.

In particular,anyValue % 1 is silly because it will always return 0.

在我的情况下,anyValue是一个双倍.这对我来说是as intended.以下是实际代码:

double v = Double.parseDouble(Utils.formatDouble(Double.valueOf(value.getValue()),accuracy.intValue()));
boolean negative = v < 0;
v = Math.abs(v);
long deg = (long) Math.floor(v);

v = (v % 1) * 60;

分析仪假设我的变量是一个int(这是他们的错误)?还是我还缺少别的东西?

解决方法

这确实是一个错误,所以非常感谢报告.

问题在这里代码:https://github.com/SonarSource/sonar-java/blob/3.9/java-checks/src/main/java/org/sonar/java/checks/ConstantMathCheck.java#L117

其中绝对没有检查%操作符的左操作数的类型.

我刚刚提交了以下错误来处理:https://jira.sonarsource.com/browse/SONARJAVA-1457

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读