...
Floating-point division by zero also results in undefined behavior, although most implementations do not treat this as a terminal error. If additional precautions are not taken, this results in a silent error.
The most portable way of determining if a floating-point exceptional condition has occurred is to use the floating-point exception facilities provided by C99 in {{ Wiki Markup fenv.h
}} \[ [ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\].
However, the C99 floating-point exception functions are not without problems. The following caveats exist regarding the interaction between floating-point exceptions and conversions:
...
Operating System | How to handle floating point errors | |||||
---|---|---|---|---|---|---|
Linux | Use the C99 floating-point exception functions. | |||||
Windows | Either | <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="422c4089-8741-4d7e-81a3-fba2472cde83"><ac:plain-text-body><![CDATA[ | Windows | Either use the C99 floating-point exception function or structured exception handling through | AA. Bibliography#MSDN]] | ]] ></ac:plain-text-body></ac:structured-macro> |
Noncompliant Code Example
...
MITRE CWE: CWE-369, "Divide By Zero"
Bibliography
...
\[[IEEE 754|AA. Bibliography#IEEE 754 2006]\]
\[[Intel 2001|AA. Bibliography#Intel 01]\]
\[[Keil 2008|AA. Bibliography#Keil 08]\]
\[[MSDN|AA. Bibliography#MSDN]\] "[fpieee_flt (CRT)|http://msdn.microsoft.com/en-us/library/te2k2f2t(VS.80).aspx]"
\[[Open Group 2004|AA. Bibliography#Open Group 04]\] "[{{fenv.h}} - Floating-point environment|http://www.opengroup.org/onlinepubs/009695399/basedefs/fenv.h.html]"
\[[SecurityFocus 2007|AA. Bibliography#SecurityFocus 07]\]
[Intel 2001]
[Keil 2008]
[MSDN] "fpieee_flt (CRT)"
[Open Group 2004] "fenv.h
- Floating-point environment"
[SecurityFocus 2007]
...
FLP02-C. Avoid using floating point numbers when precise computation is needed 05. Floating Point (FLP) FLP04-C. Check floating point inputs for exceptional values