C Programming/fenv.h

From Wikibooks, open books for an open world
Jump to navigation Jump to search

fenv.h is a header file containing various functions and macros for manipulating the floating-point environment.[1]

This header declares two types, fenv_t (represents the whole floating-point environment) and fexcept_t (represents the floating-point status flags).[1] It also declares several feature macros, beginning with FE_ and a capital letter.

Functions[edit | edit source]

Other than fegetround and fetestexcept, these functions return zero/non-zero on success/failure.

Declaration Description
int feclearexcept(int excepts); clear exceptions specified by excepts
int fegetenv(fenv_t *penv); store current floating-point environment in penv
int fegetexceptflag(fexcept_t *pflag, int excepts); store current status flags in pflags
int fegetround(void); retrieve current rounding direction
int feholdexcept(fenv_t *penv); save current floating-point environment to penv and clear all exceptions
int feraiseexcept(int excepts); raise floating-point exceptions
int fesetenv(const fenv_t *penv); set current floating-point environment to penv
int fesetexceptflag(const fexcept_t *pflags, int excepts); set current status flags to those stored in pflags
int fesetround(int round); set current rounding direction to round
int fetestexcept(int excepts); test whether certain exceptions have been raised
int feupdateenv(const fenv_t *penv); restore floating-point environment penv, but keep current exceptions
int fesetprec(int prec) Sets the precision mode to the value specified by prec.

References[edit | edit source]

  1. a b fenv.h: floating-point environment – Base Definitions Reference, The Single UNIX® Specification, Issue 7 from The Open Group