Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 Section 7.6.2 [ISO/IEC 9899:2011]). Nevertheless, these functions are the most portable solution for handling floating-point exceptions.

...

CERT C++ Secure Coding Standard: FLP03-CPP. Detect and handle floating point errors

ISO/IEC 9899:2011 Section 7.6, "Floating-point environment"

MITRE CWE: CWE-369, "Divide by zero"

...