...
This solution replaces the float
with a double
. Furthermore, it uses a static assertion to guarantee that the double
type can represent any int
without loss of precision. (See guideline recommendation DCL03-C. Use a static assertion to test the value of a constant expression.)
...
Casting numeric types to floating-point types may can lose information.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
FLP36-C | low | unlikely | medium | P2 | L3 |
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
CERT C++ Secure Coding Standard: FLP36-CPP. Beware of precision loss when converting integral types to floating point
Java The CERT Oracle Secure Coding Standard for Java: INT03-J. Do not cast numeric types to wider floating-point types without range checking
...
\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] 6.3.1.4: "Real floating and integer" Wiki Markup
Bibliography
...
FLP35-C. Take granularity into account when comparing floating point values 05. Floating Point (FLP) FLP37-C. Cast the return value of a function that returns a floating point type