常量 | 值 | 说明 |
MATH_ERRNO | 1 | errno用于表示错误:
-对于域错误:errno设置为EDOM。 -对于范围错误(极点错误,上溢出和下溢):errno设置为 ERANGE. |
MATH_ERREXCEPT | 2 | C异常:
-域错误: FE_INVALID被触发。 -极点错误: FE_DIVBYZERO被触发。 -在溢出时: FE_OVERFLOW被触发。 -对于下溢出: FE_UNDERFLOW可能被触发。 |
MATH_ERRNO|MATH_ERREXCEPT | 3 | 以上两种 |
/* 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
errno | 错误码(宏) |