...
Converting integer values to floating-point types whose mantissa has fewer bits than the original integer value can result in a rounding error.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
NUM13-J | Low | Unlikely | Medium | P2 | L3 |
Automated Detection
Automatic detection of casts that can lose precision is straightforward. Sound determination of whether those casts correctly reflect the intent of the programmer is infeasible in the general case. Heuristic warnings could be useful.
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
CodeSonar |
| JAVA.CAST.FTRUNC | Cast: Integer to Floating Point (Java) | ||||||
Parasoft Jtest |
|
|
|
CERT. |
NUM13.AIC |
Avoid implicit casts from integer data types to floating point data types | |||||||||
PVS-Studio |
| V6011 |
Related Guidelines
Bibliography
...
...