C++ - <cfenv> (fenv.h)
The C++ <cfenv> header file declares a set of functions and macros to work with the floating-point environment. The floating-point environment is the set of floating-point status flags and control modes. Specific about the contents of the floating-point environment depend on the implementation, but the status flags generally include the floating-point exceptions and their associated information, and the control modes include at least the rounding direction.
Note: The library <cfenv> was a part of C++11, the second major version of C++ and the most important update since C++98.
Library Functions
Floating-point Exceptions
Functions | Description |
---|---|
feclearexcept() | Clears floating-point exceptions. |
feraiseexcept() | Raises floating-point exceptions. |
fegetexceptflag() | Gets floating-point exceptions. |
fesetexceptflag() | Sets floating-point exceptions. |
Rounding direction
Functions | Description |
---|---|
fegetround() | Get rounding direction mode. |
fesetround() | Set rounding direction mode. |
Entire environment
Functions | Description |
---|---|
fegetenv() | Gets floating-point environment. |
fesetenv() | Sets floating-point environment. |
feholdexcept() | Holds floating-point exceptions. |
feupdateenv() | Updates floating-point environment. |
Others
Functions | Description |
---|---|
fetestexcept() | Test for floating-point exceptions. |
Library Macros
Floating-point Exceptions
Macros | Description |
---|---|
FE_DIVBYZERO | Pole error exception |
FE_INEXACT | Inexact result exception |
FE_INVALID | Invalid argument exception |
FE_OVERFLOW | Overflow range error exception |
FE_UNDERFLOW | Underflow range error exception |
FE_ALL_EXCEPT | All exceptions |
Rounding directions
Macros | Description |
---|---|
FE_DOWNWARD | Rounding towards negative infinity. |
FE_TONEAREST | Rounding towards nearest representable value. |
FE_TOWARDZERO | Rounding towards zero. |
FE_UPWARD | Rounding towards positive infinity. |
Entire environment
Macros | Description |
---|---|
FE_DFL_ENV | Default environment. |
Library Pragmas
Pragmas | Description |
---|---|
FENV_ACCESS | Access to Floating-point environment. |