Versions Compared

Key

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

...

However, for some functions it is not practical to use bounds checking to prevent all errors.  In the above pow example, the bounds check does not prevent the pow(10., 1e6) range error. In these cases detection must be used, either in addition to bounds checking or instead of bounds checking.

Anchor
ArcTrig
ArcTrig

acos

...

(error), asin

...

(error)

Non-Compliant Code Example

...

Code Block
bgColor#FFcccc
double x;
double y; 
double result;

/* Set the value for x and y */

result = atan2(y, x);

...

Code Block
bgColor#ccccff
double x;
double y; 
double result;

/* Set the value for x and y */

if ( (x == 0.f) && (y == 0.f) ) {
     /* handle domain error */
}

result = atan2(y, x);

Anchor
Log
Log

log

...

(error), log10

...

(error)

Non-Compliant Code Example

...

Code Block
bgColor#ffcccc
double x;
double y;
double result;

if (((x == 0.f) && islessequal(y, 0)) ||
    (isless(x, 0))) {
  /* handle domain and range errors */
}

result = pow(x, y);

Anchor
Sqrt
Sqrt

sqrt

...

(error)

Non-Compliant Code Example

...

Code Block
bgColor#ccccff
#include <math.h>
#if defined(math_errhandling) \
  && (math_errhandling & MATH_ERREXCEPT)
#include <fenv.h>
#endif

/* ... */

#if defined(math_errhandling) \
  && (math_errhandling & MATH_ERREXCEPT)
  feclearexcept(FE_ALL_EXCEPT);
#endif
errno = 0;

/* call the function */

#if !defined(math_errhandling) \
  || (math_errhandling & MATH_ERRNO)
if (errno != 0) {
  /* handle error */
}
#endif
#if defined(math_errhandling) \
  && (math_errhandling & MATH_ERREXCEPT)
if (fetestexcept(FE_INVALID 
               | FE_DIVBYZERO 
               | FE_OVERFLOW) != 0) 
{
  /* handle error */
}
#endif

...

Wiki Markup
\[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] Section 7.3, "Complex arithmetic <complex.h><{{complex.h}}>", and Section 7.12, "Mathematics <math.h><{{math.h}}>"
\[[Plum 85|AA. C References#Plum 85]\] Rule 2-2
\[[Plum 89|AA. C References#Plum 91]\] Topic 2.10, "conv - conversions and overflow"

...