这个 feupdateenv() C++中的函数首先保存当前引发的浮点异常。它从给定的值恢复浮点环境 fenv_t物体 然后引发以前保存的异常。 语法:
null
int feupdateenv( fenv_t* envp )
参数: 它只接受一个强制参数 envp 它指定指向fenv_t对象的指针,该对象由之前对的调用设置 feholdexcept 或 费格滕 或者等于 FE_DFL_ENV 。该函数还接受fenv_t类型的指针作为其参数,该指针保存以前使用feholdexcept或fegetenv设置的浮点环境,并将该浮点环境与当前环境一起恢复。 返回值: 该函数返回以下两种类型的值:
- 如果成功,回报率为零
- 失败时返回非零值
下面的程序说明了上述功能。 项目1:
CPP
// C++ program to illustrate the // feupdateenv() function #include <bits/stdc++.h> #pragma STDC FENV_ACCESS on // Function to use the function double answer( double y) { // struct defined fenv_t trial; // use the function feholdexcept feholdexcept(&trial); // find log value y = log (y); // clears exception feclearexcept(FE_OVERFLOW | FE_DIVBYZERO); // call the function for success or not feupdateenv(&trial); return y; } int main() { // It is a combination of all of // the possible floating-point exception feclearexcept(FE_ALL_EXCEPT); // it returns the log value // if it is to be found printf (" log (0.0): %f", answer(0.0)); // the function does not throws any exception if (!fetestexcept(FE_ALL_EXCEPT)) { printf ("no exceptions raised"); } return 0; } |
输出:
log(0.0): -infno exceptions raised
项目2:
CPP
// C++ program to illustrate the // feupdateenv() function #include <bits/stdc++.h> #pragma STDC FENV_ACCESS on // Function to use the function double answer( double y) { // struct defined fenv_t trial; // use the function feholdexcept feholdexcept(&trial); // find log value y = log (y); // clears exception feclearexcept(FE_OVERFLOW | FE_DIVBYZERO); // call the function for success or not feupdateenv(&trial); return y; } int main() { // It is a combination of all of // the possible floating-point exception feclearexcept(FE_ALL_EXCEPT); // it returns the log value // if it is to be found printf (" log (10.0): %f", answer(10.0)); // the function does not throws any exception if (!fetestexcept(FE_ALL_EXCEPT)) { printf ("no exceptions raised"); } else printf ("exceptions raised"); return 0; } |
输出:
log(10.0): 2.302585exceptions raised
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END