C++ <cfenv> - FE_INVALID
The FE_INVALID 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 invalid arguments.
Invalid argument exceptions are raised when the argument passed to a function is out of its domain (function is not defined for that value), for example - sqrt(-1.0). The value returned by a function that raises this exception is unspecified.
Definition in the <cfenv> header file is:
#define FE_INVALID /*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_INVALID macro.
#include <iostream> #include <cfenv> #include <cmath> using namespace std; int main (){ cout<<"sqrt(-1.0) = "<<sqrt(-1)<<"\n"; if(fetestexcept(FE_INVALID)) cout<<"Domain error is reported.\n"; else cout<<"Domain error is not reported.\n"; return 0; }
The output of the above code will be:
sqrt(-1.0) = -nan Domain error is reported.
❮ C++ <cfenv> Library