CERT-FLP32-C_b
In this section:
Synopsis
Prevent or detect domain and range errors in math functions.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
Range errors usually cannot be prevented because they are dependent on the implementation of floating-point numbers as well as on the function being applied. Instead of preventing range errors, programmers should attempt to detect them and take alternative action if a range error occurs.
Coding standards
- CERT FLP32-C
Prevent or detect domain and range errors in math functions
Code examples
The following code example fails the check and will give a warning:
#include <math.h>
void example(double x) {
double result;
result = sinh(x);
}
The following code example passes the check and will not give a warning about this issue:
#include <math.h>
#include <fenv.h>
#include <errno.h>
void example(double x) {
double result;
{
if (math_errhandling & MATH_ERREXCEPT) {
feclearexcept(FE_ALL_EXCEPT);
}
errno = 0;
result = sinh(x);
if ((math_errhandling & MATH_ERRNO) && errno != 0) {
return;
} else if ((math_errhandling & MATH_ERREXCEPT) &&
fetestexcept(FE_INVALID | FE_DIVBYZERO |
FE_OVERFLOW | FE_UNDERFLOW) != 0) {
return;
}
}
}