Important: The information in this document is obsolete and should not be used for new development.
feholdexcept
You can use thefeholdexcept
function to save the current floating-point environment and then clear all exception flags.
int feholdexcept (fenv_t *envp);
envp
- A pointer to an environment word where the environment should be saved.
DESCRIPTION
Thefeholdexcept
function stores the current environment in the argumentenvp
and clears the floating-point exception flags. Note that this function does not affect the rounding direction. It is the same as performing the following two calls:
fegetenv(envp); feclearexcept(FE_ALL_EXCEPT);Callfeholdexcept
at the beginning of a function so that the function can start with all exceptions cleared but not change the caller's environment. Usefeupdateenv
to restore the caller's environment at the end of the function. Thefeupdateenv
function keeps any exceptions raised by the current function set while restoring the rest of the caller's environment. Thus, usingfeholdexcept
andfeupdateenv
together preserves all raised floating-point exceptions while allowing new ones to be raised as well.EXAMPLES
void subroutine(void) { fenv_t *e; /* local storage for environment */ feholdexcept(e); /* save caller's environment and clear exceptions */ /* subroutine's operations here */ feupdateenv(e); /* restore caller's environment */ }