fegetexceptflag() function in C/C++
The fegetexceptflag() function in C/C++ is specified in header file fenv.h and gets floating point exception flags. This function store the raised exception in the point specified by flagp .
Syntax:
int fegetexceptflag(fexcept_t* flagp, int excepts)
Parameters: The function accepts two mandatory parameters which are described below:
- flagp : signifies the pointer to a fexcept_t object where the representation is stored.
- excepts : signifies the bitmask value.
Macro –> Description:
- FE_DIVBYZERO –> Pole error: Division by zero.
- FE_INEXACT –> Inexact: The result is not exact.
- FE_INVALID –> Domain error: At least one of the arguments is a value for which the function is not defined.
- FE_OVERFLOW –> Overflow range error: The result is too large.
- FE_UNDERFLOW –> Underflow range error: The result is too small.
- FE_ALL_EXCEPT –> All exceptions.
Return value : The function returns two value as below:
- Zero: on success.
- Non-zero: on failure
Below programs illustrate the above function:
Program 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 -> \n"; // print the exception occurred if (fetestexcept(FE_ALL_EXCEPT)) { if (fetestexcept(FE_DIVBYZERO)) cout << "FE_DIVBYZERO \n"; if (fetestexcept(FE_INEXACT)) cout << "FE_INEXACT \n"; if (fetestexcept(FE_INVALID)) cout << "FE_INVALID \n"; if (fetestexcept(FE_OVERFLOW)) cout << "FE_OVERFLOW \n"; if (fetestexcept(FE_UNDERFLOW)) cout << "FE_UNDERFLOW \n"; if (fetestexcept(FE_ALL_EXCEPT)) cout << "FE_ALL_EXCEPT \n"; } else cout << "None"; return 0; } |
Exception raised -> FE_DIVBYZERO FE_ALL_EXCEPT
Program 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 -> \n"; // print the exception occurred if (fetestexcept(FE_ALL_EXCEPT)) { if (fetestexcept(FE_DIVBYZERO)) cout << "FE_DIVBYZERO \n"; if (fetestexcept(FE_INEXACT)) cout << "FE_INEXACT \n"; if (fetestexcept(FE_INVALID)) cout << "FE_INVALID \n"; if (fetestexcept(FE_OVERFLOW)) cout << "FE_OVERFLOW \n"; if (fetestexcept(FE_UNDERFLOW)) cout << "FE_UNDERFLOW \n"; if (fetestexcept(FE_ALL_EXCEPT)) cout << "FE_ALL_EXCEPT \n"; } else cout << "None"; return 0; } |
Exception raised -> FE_DIVBYZERO FE_INEXACT FE_INVALID FE_OVERFLOW FE_UNDERFLOW FE_ALL_EXCEPT
Recommended Posts:
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- exp() function C++
- log() function in C++
- div() function in C++
- arc function in C
- fma() function in C++
- valarray exp() function in C++
- ios eof() function in C++ with Examples
- valarray sin() function in C++
- valarray abs() function in C++
- valarray end() function in C++
- map rbegin() function in C++ STL
- valarray tan() function in C++
- valarray cos() function in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


