📅  最后修改于: 2020-09-25 07:18:21             🧑  作者: Mango
feupdateenv() 函数在
int feupdateenv( fenv_t* envp );
feupdateenv() 函数将类型为fenv_t的指针作为其参数,该指针保存先前通过使用feholdexcept或fegetenv设置的浮点环境,并将该浮点环境与当前环境一起还原。
#include
#include
#include
#pragma STDC FENV_ACCESS ON
using namespace std;
void print_exceptions()
{
cout << "Raised exceptions: ";
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 ";
}
else
cout << "None";
cout << endl;
}
int main()
{
fenv_t envp;
/* raise certain exceptions */
feraiseexcept(FE_INVALID|FE_DIVBYZERO);
print_exceptions();
/* saves and clears current exceptions */
feupdateenv(&envp);
print_exceptions();
/* restores saved exceptions */
feupdateenv(&envp);
print_exceptions();
return 0;
}
运行该程序时,输出为:
Raised exceptions: FE_DIVBYZERO FE_INVALID
Raised exceptions: None
Raised exceptions: FE_DIVBYZERO FE_INVALID