
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
65 lines
1.3 KiB
Plaintext
65 lines
1.3 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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:
|
|
|
|
[frame=all]
|
|
[cols="^1,^1"]
|
|
|===
|
|
|Operation|Value
|
|
|
|
|acos|0.0 or 1.0
|
|
|asin|0.0 or 1.0
|
|
|atan|0.0 or 1.0
|
|
|atan2|0.0
|
|
|cbrt|0.0 or 1.0
|
|
|cos|0.0
|
|
|cosh|0.0
|
|
|exp|0.0 or 1.0
|
|
|expm1|0.0
|
|
|log|0.0 or 1.0
|
|
|log10|0.0 or 1.0
|
|
|sin|0.0
|
|
|sinh|0.0
|
|
|sqrt|0.0 or 1.0
|
|
|tan|0.0
|
|
|tanh|0.0
|
|
|toDegrees|0.0 or 1.0
|
|
|toRadians|0.0
|
|
|===
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
public void doMath(int a) {
|
|
double floor = Math.floor((double)a); // Noncompliant
|
|
double ceiling = Math.ceil(4.2); // Noncompliant
|
|
double arcTan = Math.atan(0.0); // Noncompliant
|
|
}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove this silly call to "Math.xxx".
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|