Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Changed to Applicability and updated the reference to Java 7

...

As in the first compliant example, the value of c cannot be represented exactly as a double. Consequently, the value of f is not precise before or after the multiplication. The explanation and consequences are identical to those stated previously.

Exceptions

Applicability

Improper conversions between integers and floating-point values can yield unexpected results, especially from precision loss. In some cases, these unexpected results can involve overflow or undefined behavior.

NUM50-EX0: It is acceptable to perform operations using a mix of integer and floating-point values when deliberately exploiting the properties of integer arithmetic before conversion to floating point. For example, using integer arithmetic eliminates the need to use the floor() method. Any such code must be clearly documented to help future maintainers understand that this behavior is intentional.

Risk Assessment

Improper conversions between integers and floating-point values can yield unexpected results, especially from precision loss. In some cases, these unexpected results can involve overflow or undefined behavior.

Guideline

Severity

Likelihood

Remediation Cost

Priority

Level

NUM50-JG

low

probable

low

P6

L2

Automated Detection

Automated detection is not feasible in the general case. Heuristic checking could be useful.

Related Guidelines

Bibliography

...