Narrower primitive types can be cast to wider types without affecting the magnitude of numeric values. However, when the expressions are not strictfp (guideline FLP04-J. Use the strictfp modifier for floating point calculation consistency), conversions from float
to double
may lose information about the overall magnitude of the converted value (see . See JLS Section 5.1.2, Widening Primitive Conversion) for more information.
Conversion from int
or long
to float
, or long
to double
can lead to loss of precision (loss of least significant bits). No runtime exception occurs despite this loss. Also, see guideline EXP05-J. Be aware of integer promotions in binary operators.
...
Casting numeric types to wider floating-point types may lose information.
Rule Guideline | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
INT03-J | low | unlikely | medium | P2 | L3 |
...