Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library

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.

Library Functions

Floating-point Exceptions

feclearexcept() Clears floating-point exceptions.
feraiseexcept() Raises floating-point exceptions.
fegetexceptflag() Gets floating-point exceptions.
fesetexceptflag() Sets floating-point exceptions.

Rounding direction

fegetround() Get rounding direction mode.
fesetround() Set rounding direction mode.

Entire environment

fegetenv() Gets floating-point environment.
feholdexcept() Holds floating-point exceptions.

Library Macros

Floating-point Exceptions

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

FE_DOWNWARD Rounding towards negative infinity.
FE_TONEAREST Rounding towards nearest representable value.
FE_TOWARDZERO Rounding towards zero.
FE_UPWARD Rounding towards positive infinity.

Library Pragmas

FENV_ACCESS Access to Floating-point environment.

Library Types

fenv_t Floating-point environment type.
fexcept_t Floating-point exceptions type.