Some mathematical operations are unnecessary and should not be performed because their results are predictable.
For instance, anyValue % 1 will always return 0, as any integer value can be divided by 1 without remainder.
Similarly, casting a non-floating-point to a floating-point value and then passing it to Math.round, Math.ceil, or
Math.floor is also unnecessary, as the result will always be the original value.
The following operations are unnecessary when given any constant value: Math.abs, Math.ceil, Math.floor,
Math.rint, Math.round. Instead, use the result of the operation directly.
The following operations are unnecessary with certain constants and can be replaced by the result of the operation directly:
| 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 |