...
The most portable way of determining if a floating-point exceptional condition has occurred is to use the floating-point exception facilities provided by C in fenv.h
[ISO/IEC 9899:2011].
However, the C floating-point exception functions are not without problems. The following caveats exist regarding the interaction between floating-point exceptions and conversions:
...
The C standard does not require all implementations to support floating-point exceptions. Each exception macro in fenv.h
is defined if, and only if, the corresponding exception is supported. Only implementations that use IEC 60559 (formerly IEEE-754) floating-point arithmetic are required to support all five exceptions defined by C (see the C Standard, Section 7.6.2 [ISO/IEC 9899:2011]). Nevertheless, these functions are the most portable solution for handling floating-point exceptions.
...
However, exceptional conditions (as indicated by the comments) occur that may lead to unexpected arithmetic results.
Compliant Solution (
...
C)
This compliant solution uses C standard Standard functions to handle floating-point errors.
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
Compass/ROSE |
|
| Could detect violations of this rule by ensuring that floating-point operations are surrounded by | ||||||
PRQA QA-C |
| 4123 | Partially implemented. |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this recommendation on the CERT website.
Related Guidelines
...
ISO/IEC 9899:2011 Section 7.6, "Floating-point environment"
...
...
Divide by zero |
...
Bibliography
[IEEE 754] | |
---|---|
[Intel 2001] | |
[Keil 2008] | |
[MSDN] | "fpieee_flt (CRT)" |
[Open Group 2004] | "fenv.h - Floating-point environment" |
[SecurityFocus 2007] |
...