feraiseexcept
在头文件<fenv.h>中定义 | | |
---|---|---|
int feraiseexcept(int excepts); | | (自C99以来) |
尝试提升excepts中列出的所有浮点异常(浮点异常宏的按位或)。 如果其中一个例外是FE_OVERFLOW或FE_UNDERFLOW,则此函数可能会额外引发FE_INEXACT。 除非在FE_INEXACT之前始终引发FE_OVERFLOW和FE_UNDERFLOW,否则未指定异常的顺序。
参数
excepts | - | bitmask listing the exception flags to raise |
---|
返回值
如果列出的所有异常均为0,则返回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");
feclearexcept(FE_ALL_EXCEPT);
printf("\n");
}
double some_computation(void)
{
/* Computation reaches a state that causes overflow. */
int r = feraiseexcept(FE_OVERFLOW | FE_INEXACT);
printf("feraiseexcept() %s\n", (r?"fails":"succeeds"));
return 0.0;
}
int main(void)
{
some_computation();
show_fe_exceptions();
return 0;
}
输出:
feraiseexcept() succeeds
current exceptions raised: FE_INEXACT FE_OVERFLOW
参考
- C11标准(ISO / IEC 9899:2011):
- 7.6.2.3 feraiseexcept函数(p:210)
- C99标准(ISO / IEC 9899:1999):
- 7.6.2.3 feraiseexcept函数(p:191)
扩展内容
feclearexcept(C99) | 清除指定的浮点状态标志(函数) |
---|---|
fetestexcept(C99) | 确定哪个指定的浮点状态标志被设置(功能) |
| 用于feraiseexcept的C ++文档 |
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com