Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: couple tweaks, replaced period with comma, etc.

Incautious use of integer arithmetic to calculate a value for assignment to a floating-point variable can lead to loss of information. For example, integer arithmetic always produces integral results, discarding information about any possible fractional remainder. Furthermore, there can be loss of precision when converting integers to floating-point values. See  NUM13-J. Avoid loss of precision when converting primitive integers to floating-point for additional information. Correct programming of expressions that mix combine integer and floating-point operations or values requires careful consideration.

...

Note that the calculation for c also violates  violates NUM00-J. Detect or prevent integer overflow.

...

This compliant solution casts the divisor to double before the division is performed. Consequently, the numerator is automatically promoted to double, the division operation becomes a double divide. , and value is assigned the correct result. As in the previous compliant solution, this practice ensures that at least one of the operands of each operation is a floating-point number.

...