C/C中的fegetexceptflag()函数++

这个 fegetexceptflag() C/C++中的函数在头文件中指定 芬夫。H 并获取浮点异常标志。此函数将引发的异常存储在 弗拉格 .

null

语法:

int fegetexceptflag(fexcept_t* flagp, int excepts)

参数: 该函数接受两个强制参数,如下所述:

  • flagp: 表示指向 除此之外 存储表示的对象。
  • 例外情况: 表示位掩码值。

–> 描述 :

  1. F_DIVBYZERO 极差:除零。
  2. 不精确 不准确:结果不准确。
  3. F_无效 –>域错误:至少有一个参数是未定义函数的值。
  4. 溢流 –>溢出范围错误:结果太大。
  5. 底流 –>底流范围错误:结果太小。
  6. 除了 –>所有例外情况。

返回值: 该函数返回两个值,如下所示:

  • 零:关于成功。
  • 非零:关于失败

以下程序说明了上述功能: 项目1:

// C++ program to illustrate
// fegetexceptflag() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// bitmask value
fexcept_t excepts;
// divided by zero exception
feraiseexcept(FE_DIVBYZERO);
// current state is saved
fegetexceptflag(&excepts, FE_ALL_EXCEPT);
cout << "Exception raised -> " ;
// print the exception occurred
if (fetestexcept(FE_ALL_EXCEPT)) {
if (fetestexcept(FE_DIVBYZERO))
cout << "FE_DIVBYZERO " ;
if (fetestexcept(FE_INEXACT))
cout << "FE_INEXACT " ;
if (fetestexcept(FE_INVALID))
cout << "FE_INVALID " ;
if (fetestexcept(FE_OVERFLOW))
cout << "FE_OVERFLOW " ;
if (fetestexcept(FE_UNDERFLOW))
cout << "FE_UNDERFLOW " ;
if (fetestexcept(FE_ALL_EXCEPT))
cout << "FE_ALL_EXCEPT " ;
}
else
cout << "None" ;
return 0;
}


输出:

Exception raised -> 
FE_DIVBYZERO 
FE_ALL_EXCEPT

项目2:

// C++ program to illustrate
// fegetexceptflag() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// bitmask value
fexcept_t excepts;
// raised exception
feraiseexcept(FE_ALL_EXCEPT);
// current state is saved
fegetexceptflag(&excepts, FE_ALL_EXCEPT);
cout << "Exception raised -> " ;
// print the exception occurred
if (fetestexcept(FE_ALL_EXCEPT)) {
if (fetestexcept(FE_DIVBYZERO))
cout << "FE_DIVBYZERO " ;
if (fetestexcept(FE_INEXACT))
cout << "FE_INEXACT " ;
if (fetestexcept(FE_INVALID))
cout << "FE_INVALID " ;
if (fetestexcept(FE_OVERFLOW))
cout << "FE_OVERFLOW " ;
if (fetestexcept(FE_UNDERFLOW))
cout << "FE_UNDERFLOW " ;
if (fetestexcept(FE_ALL_EXCEPT))
cout << "FE_ALL_EXCEPT " ;
}
else
cout << "None" ;
return 0;
}


输出:

Exception raised -> 
FE_DIVBYZERO 
FE_INEXACT 
FE_INVALID 
FE_OVERFLOW 
FE_UNDERFLOW 
FE_ALL_EXCEPT

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享