c语言 ip->flag,fegetexceptflag

在头文件中定义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 #include 

#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):7.6.2.2 fegetexcept标志功能(p:210)

7.6.2.4 fesetexcept标志功能(p:211)

C99标准(ISO / IEC 9899:1999):7.6.2.2 fegetexcept标志功能(p:191)

7.6.2.4 fesetexceptflag函数(p:192)

扩展内容

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

|:----|

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值