Floatingpoint equality checks using Double.equals and Float.equals do not trigger warnings

40 views
Skip to first unread message

Kai Ebenhöh

unread,
May 28, 2018, 8:10:49 AM5/28/18
to SonarQube
Hi,

the code:

double someDouble = 0.0d;
if( Double.valueOf(0.0).equals(someDouble) ){
 
...
}

does not trigger a sonar warning.
Since Javas Double.equals uses Double.doubleToLongBits, it's just as unsafe for comparing floatingpoint numbers as the == equality check.

References: RSPEC-1244 and SONARJAVA-722

Rregards,
Kai

Andrei Epure

unread,
Jun 8, 2018, 12:03:41 PM6/8/18
to SonarQube
Hello Kai,

Thanks, I've opened SONARJAVA-2787

Regards,
Andrei

Andrei Epure | SonarSource

Software Developer

https://sonarsource.com


Are you using SonarLint in your IDE?


Reply all
Reply to author
Forward
0 new messages