C Standard Library

C - <fenv.h>



The C <fenv.h> 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 <fenv.h> was a part of extension, adopted by ANSI in 2000, commonly referred to as C99.

Library Functions

Floating-point Exceptions

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

Rounding direction

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

Entire environment

FunctionsDescription
fegetenv() Gets floating-point environment.
fesetenv() Sets floating-point environment.
feholdexcept() Holds floating-point exceptions.
feupdateenv() Updates floating-point environment.

Others

FunctionsDescription
fetestexcept() Test for floating-point exceptions.

Library Macros

Floating-point Exceptions

MacrosDescription
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

MacrosDescription
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

MacrosDescription
FE_DFL_ENV Default environment.

Library Pragmas

PragmasDescription
FENV_ACCESS Access to Floating-point environment.

Library Types

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