...
Note that conversions from float
to double
or from double
to float
can also lose information about the overall magnitude of the converted value. See rule NUM06 NUM53-J. Use the strictfp modifier for floating-point calculation consistency across platforms for additional information.
...
Automated detection of narrowing conversions on integral types is straightforward. Determining whether such conversions correctly reflect the intent of the programmer is infeasible in the general case. Heuristic warnings could be useful.
Related Guidelines
INT31-C. Ensure that integer conversions do not result in lost or misinterpreted data | |
| FLP34-C. Ensure that floating-point conversions are within range of the new type |
VOID INT31-CPP. Ensure that integer conversions do not result in lost or misinterpreted data | |
| VOID FLP34-CPP. Ensure that floating point conversions are within range of the new type |
Numeric Conversion Errors [FLC] | |
CWE-681. Incorrect conversion between numeric types | |
| CWE-197. Numeric truncation error |
...
| |
[JLS 2005] | |
[Seacord 2015] | NUM12-J. Ensure conversions of numeric types to narrower types do not result in lost or misinterpreted data LiveLesson |
...