int
| constant | value | description |
|---|---|---|
| MATH_ERRNO | 1 | errno is used to signal errors: - On domain error: errno is set to EDOM . - On range error (including pole error, overflow, and possibly underflow): errno is set to ERANGE . |
| MATH_ERREXCEPT | 2 | The proper C exception is raised: - On domain error: FE_INVALID is raised. - On pole error: FE_DIVBYZERO is raised. - On overflow: FE_OVERFLOW is raised. - On underflow: FE_UNDERFLOW may be raised. |
| MATH_ERRNO|MATH_ERREXCEPT | 3 | Both of the above |
1 and 2 respectivelly.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* math_errhandling example */
#include <stdio.h> /* printf */
#include <math.h> /* math_errhandling */
#include <errno.h> /* errno, EDOM */
#include <fenv.h> /* feclearexcept, fetestexcept, FE_ALL_EXCEPT, FE_INVALID */
#pragma STDC FENV_ACCESS on
int main () {
errno = 0;
if (math_errhandling & MATH_ERREXCEPT) feclearexcept(FE_ALL_EXCEPT);
printf ("Error handling: %d",math_errhandling);
sqrt (-1);
if (math_errhandling & MATH_ERRNO) {
if (errno==EDOM) printf("errno set to EDOM\n");
}
if (math_errhandling &MATH_ERREXCEPT) {
if (fetestexcept(FE_INVALID)) printf("FE_INVALID raised\n");
}
return 0;
}
Error handling: 3 errno set to EDOM FE_INVALID raised