Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: few minor changes including changing "loss of precision" to "roundnig error" in risk assessment

...

Note that conversions from float to double can also lose information about the overall magnitude of the converted value. Specifically, on platforms whose native floating point hardware provides greater precision than double, the JIT is permitted to use floating point registers to hold values of type float or type double (in the absence of the strictfp modifier), even though the registers support values with greater mantissa and/or exponent range than that of the primitive types. Consequently, conversion from float to double can cause an effective loss of precision, of magnitude, or of both. However, the lost precision or magnitude would also have been lost if the value were stored to memory, for example to a field of type float. See guideline NUM04-J. Use the strictfp modifier for floating point calculation consistency for additional information.

...

In this example, the subFloatFromInt() method throws java.lang.ArithmeticException. This general approach, with appropriate range checks, should be used for conversions from long to either float or double.

...

Note that this compliant solution is insufficient cannot be used when the primitive integers are of type long, because Java lacks a primitive floating point type whose mantissa can represent the full range of a long.

...

Converting integer values to floating-point types whose mantissa has fewer bits than the original integer value will lose precisionmay result in a rounding error.

Guideline

Severity

Likelihood

Remediation Cost

Priority

Level

NUM10-J

low

unlikely

medium

P2

L3

...