All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S2185.html Maven / Gradle / Ivy

There is a newer version: 8.6.0.37351
Show newest version

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.

Casting a non-floating-point value to floating-point and then passing it to Math.round, Math.ceil, or Math.floor is silly because the result will always be the original value.

These operations are silly with any constant value: Math.abs, Math.ceil, Math.floor, Math.rint, Math.round.

And these oprations are silly with certain constant values:

OperationValue
acos0.0 or 1.0
asin0.0 or 1.0
atan0.0 or 1.0
atan20.0
cbrt0.0 or 1.0
cos0.0
cosh0.0
exp0.0 or 1.0
expm10.0
log0.0 or 1.0
log100.0 or 1.0
sin0.0
sinh0.0
sqrt0.0 or 1.0
tan0.0
tanh0.0
toDegrees0.0 or 1.0
toRadians0.0

Noncompliant Code Example

public void doMath(int a)
double floor = Math.floor((double)a); // Noncompliant
double ceiling = Math.ceil(4.2);
double arcTan = Math.atan(0.0);




© 2015 - 2025 Weber Informatics LLC | Privacy Policy