Name
fegetenv
Synopsis
Stores a copy of the current floating-point environment
#include <fenv.h> intfegetenv( fenv_t *envp);
The fegetenv() function
saves the current state of the floating-point environment in the
object referenced by the pointer argument. The function returns 0 if
successful; a nonzero return value indicates that an error
occurred.
The object type that represents the floating-point
environment, fenv_t, is defined
in fenv.h. It contains at least
two kinds of information: floating-point
status flags, which are set to indicate specific
floating-point processing exceptions, and a floating-point control mode, which can be
used to influence the behavior of floating-point arithmetic, such as
the direction of rounding.
Example
The fegetenv() and fesetenv() functions can be used to
provide continuity of the floating-point environment between
different locations in a program:
static fenv_t fpenv; // Global environment variables. static jmp_buf env; /* ... */ #pragma STDC FENV_ACCESS ONfegetenv(&fpenv); // Store a copy of the floating-point environment if ( setjmp(env) == 0 ) // setjmp() returns 0 when actually called { /* ... Proceed normally; floating-point environment unchanged ... */ } else // Nonzero return value means longjmp() occurred {fesetenv(&fpenv); // Restore floating-point environment to known state /* ... */ }
See Also
fegetexceptflag(),
feholdexcept(),
fesetenv(), feupdateenv(), feclearexcept(),
feraisexcept(), fetestexcept()
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access