fegetexceptflag, fesetexceptflag
来自 cppreference.cn
定义于头文件 <fenv.h> |
||
int fegetexceptflag( fexcept_t* flagp, int excepts ); |
(1) | (C99 起) |
int fesetexceptflag( const fexcept_t* flagp, int excepts ); |
(2) | (C99 起) |
1) 尝试获取 bitmask 参数 excepts
中列出的浮点异常标志的全部内容,excepts
是 浮点异常宏 的按位或。
2) 尝试将 excepts
中列出的浮点异常标志的全部内容从 flagp
复制到浮点环境中。不引发任何异常,只修改标志。
浮点异常标志的全部内容不一定是一个布尔值,指示异常是已引发还是已清除。例如,它可能是一个结构体,其中包括布尔状态和触发异常的代码地址。这些函数获取所有此类内容,并以实现定义格式在 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