C
数值 | Numerics

fesetexceptflag

fegetexceptflag, fesetexceptflag

在头文件中定义
int fegetexceptflag(fexcept_t * flagp,int excepts);(1)(自C99以来)
int fesetexceptflag(const fexcept_t * flagp,int excepts);(2)(自C99以来)

1)尝试获取位掩码参数excepts中列出的浮点异常标志的全部内容,这是浮点异常宏的按位或。

2)尝试将浮点异常标志的全部内容复制到浮点环境中。 不会引发任何异常,只会修改标志。

浮点异常标志的全部内容不一定是一个布尔值,指示是否引发或清除异常。 例如,它可能是一个包含布尔状态和触发异常的代码地址的结构。 这些函数获取所有这些内容并以实现定义的格式将其存储在flagp中。

参数

flagp-指向将存储或读取标志的fexcept_t对象的指针
excepts -位掩码列出异常标志以获取/设置

返回值

成功时为0,否则为非零。

#include <stdio.h> #include <fenv.h> #pragma STDC FENV_ACCESS ON void show_fe_exceptions(void) { printf("current exceptions raised: " if(fetestexcept(FE_DIVBYZERO)) printf(" FE_DIVBYZERO" if(fetestexcept(FE_INEXACT)) printf(" FE_INEXACT" if(fetestexcept(FE_INVALID)) printf(" FE_INVALID" if(fetestexcept(FE_OVERFLOW)) printf(" FE_OVERFLOW" if(fetestexcept(FE_UNDERFLOW)) printf(" FE_UNDERFLOW" if(fetestexcept(FE_ALL_EXCEPT)==0) printf(" none" printf("\n" } int main(void) { fexcept_t excepts; /* Setup a "current" set of exception flags. */ feraiseexcept(FE_INVALID show_fe_exceptions( /* Save current exception flags. */ fegetexceptflag(&excepts,FE_ALL_EXCEPT /* Temporarily raise two other exceptions. */ feclearexcept(FE_ALL_EXCEPT feraiseexcept(FE_OVERFLOW | FE_INEXACT show_fe_exceptions( /* Restore previous exception flags. */ fesetexceptflag(&excepts,FE_ALL_EXCEPT show_fe_exceptions( return 0; }

输出:

current exceptions raised: FE_INVALID current exceptions raised: FE_INEXACT FE_OVERFLOW current exceptions raised: FE_INVALID

参考

  • C11标准(ISO / IEC 9899:2011):

扩展内容

| 用于fegetexceptflag,fesetexceptflag的C ++文档 |

|:----|