📅  最后修改于: 2020-09-25 07:14:32             🧑  作者: Mango
feraiseexcept() 函数在
int feraiseexcept(int excepts);
参数中列出了要引发的浮点异常。
另外,您应该启用FENV_ACCESS ,这将使您的程序可以访问浮点环境以测试引发的异常。
Macro | Type | Description |
---|---|---|
FE_DIVBYZERO | Pole error | Division by zero |
FE_INEXACT | Inexact | Not exact results such as (1.0/3.0) |
FE_INVALID | Domain error | At least one arguments used is a value for which the function is not defined |
FE_OVERFLOW | Overflow range error | Result is too large in magnitude to be represented by the return type |
FE_UNDERFLOW | Underflow range error | Result is too small in magnitude to be represented by the return type |
FE_ALL_EXCEPT | All exceptions | All exceptions supported by the implementation |
#include
#include
#pragma STDC FENV_ACCESS ON
using namespace std;
int main()
{
int retVal;
feclearexcept(FE_ALL_EXCEPT);
retVal = feraiseexcept(FE_OVERFLOW | FE_INVALID);
if (retVal == 0)
cout << "Successfully raised FE_OVERFLOW and FE_INVALID" << endl;
else
cout << "Raising FE_OVERFLOW and FE_INVALID failed" << endl;
return 0;
}
运行该程序时,输出为:
Successfully raised FE_OVERFLOW and FE_INVALID