Important: The information in this document is obsolete and should not be used for new development.
feupdateenv
You can use thefeupdateenv
function to restore the floating-point environment previously saved withfeholdexcept
.
void feupdateenv (const fenv_t *envp);
envp
- A pointer to the word containing the environment to be restored.
DESCRIPTION
Thefeupdateenv
function, which takes a saved environment as argument, does the following:
The
- It temporarily saves the exception flags (raised by the current function).
- It restores the environment received as an argument.
- It signals the temporarily saved exceptions.
feupdateenv
function facilitates writing subroutines that appear to their callers to be atomic operations (such as addition, square root, and others). Atomic operations pass extra information back to their callers by signaling exceptions; however, they hide internal exceptions, which might be irrelevant or misleading. Thus, exceptions signaled between thefeholdexcept
andfeupdateenv
functions are hidden from the calling function unless the exceptions remain raised when thefeupdateenv
procedure is called.EXAMPLES
/* NumFcn signals underflow if its result is denormalized, overflow if its result is INFINITY, and inexact always, but hides spurious exceptions occurring from internal computations. */ long double NumFcn(void) { fenv_t e; /* local environment storage */ enum NumKind c; /* for class inquiry */ fexcept_t * flagp; long double result; feholdexcept(&e); /* save caller's environment and clear exceptions */ /* internal computation */ c = fpclassify(result); /* class inquiry */ feclearexcept(FE_ALL_EXCEPT); /* clear all exceptions */ feraiseexcept(FE_INEXACT); /* signal inexact */ if (c == FP_INFINITE) feraiseexcept(FE_OVERFLOW); else if (c == FP_SUBNORMAL) feraiseexcept(FE_UNDERFLOW); feupdateenv(&e); /* restore caller's environment, and then signal exceptions raised by NumFcn */ return(result); }