Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: PowerPC Numerics / Part 2 - The PowerPC Numerics C Implementation
Chapter 8 - Environmental Control Functions / Accessing the Floating-Point Environment


feupdateenv

You can use the feupdateenv function to restore the floating-point environment previously saved with feholdexcept.

void feupdateenv (const fenv_t *envp);
envp
A pointer to the word containing the environment to be restored.
DESCRIPTION
The feupdateenv function, which takes a saved environment as argument, does the following:

  1. It temporarily saves the exception flags (raised by the current function).
  2. It restores the environment received as an argument.
  3. It signals the temporarily saved exceptions.

The 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 the feholdexcept and feupdateenv functions are hidden from the calling function unless the exceptions remain raised when the feupdateenv 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);
}


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996