Versions Compared

Key

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

...

Operating System

How to Handle Floating-Point Errors

Linux
Solaris 10
AIX 5.3
HP-UX 11.31
Mac OS X 10.5

Use the C floating-point exception functions.

Windows

Use either the C floating-point exception functions or structured exception handling through _fpieee_flt [MSDN].

Noncompliant Code Example

...

Tool

Version

Checker

Description

Compass/ROSE

 

 

Could detect violations of this rule by ensuring that floating-point operations are surrounded by feclearexcept() and fetestexcept(). It would need to look for type conversions to float or double, divisions (by a number not known to be nonzero), and multiplication. It may be wisest to apply this to all floating-point operations in general.

PRQA QA·CQA-C
Include Page
PRQA_V
PRQA_V
 Partially implemented

...

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

Bibliography

[IEEE 754]
[Intel 2001]
[Keil 2008]
[MSDN] "fpieee_flt (CRT)"
[Open Group 2004] "fenv.h - Floating-point environment"
[SecurityFocus 2007]

...