C++ <cfenv> - FE_INEXACT
The FE_INEXACT macro expands to a value of type integer constant expression that is distinct powers of 2, which uniquely identifies the floating-point exception raised on inexact results.
Inexact exceptions are raised when the return type of an operation cannot represent the result with exact accuracy (for example - 1.0/3.0 or sqrt(2.0) on most implementations), or when a function cannot produce an exact result for some other reason.
Definition in the <cfenv> header file is:
#define FE_INEXACT /*implementation defined power of 2*/
The details about all floating-point exception macros are listed below:
Macros | Description |
---|---|
FE_DIVBYZERO | Pole error exception occurred in an earlier floating-point operation. |
FE_INEXACT | Inexact result exception occurred in an earlier floating-point operation (rounding was necessary to store the result). |
FE_INVALID | Invalid argument exception occurred (domain error occurred) in an earlier floating-point operation. |
FE_OVERFLOW | Overflow range error exception occurred in an earlier floating-point operation (result was too large to be representable). |
FE_UNDERFLOW | Underflow range error exception occurred in an earlier floating-point operation (result was subnormal with a loss of precision). |
FE_ALL_EXCEPT | Bitwise OR of all supported floating-point exceptions. |
Certain library implementations may define additional macro constants in <cfenv> to identify additional floating-point exceptions (with their corresponding macros also beginning with FE_).
See math_errhandling for more details.
Example:
The example below shows the usage of FE_INEXACT macro.
#include <iostream> #include <cfenv> #pragma STDC FENV_ACCESS ON //volatile not needed if FENV_ACCESS is supported volatile double three = 3.0; using namespace std; int main (){ cout<<"1.0/3.0 = "<<(1.0/three)<<"\n"; if(fetestexcept(FE_INEXACT)) cout<<"Inexact result is reported.\n"; else cout<<"Inexact result is not reported.\n"; return 0; }
The output of the above code will be:
1.0/3.0 = 0.333333 Inexact result is reported.
❮ C++ <cfenv> Library