feupdateenv Function

Installs the environment from an object, preserving the state of the current floating-point exceptions.

Attention: This function is implemented only by MPLAB XC32 C compilers.




void feupdateenv(fenv_t * envp);


a pointer to the object in which the environment should be stored


This function saves the current floating-point environment in automatic storage, installs the floating-point environment represented by the object pointed to by envp, and then raises the saved floating-point exceptions. The pointer argument should be pointing to an object obtained from a call to fegetenv() or feholdexcept(), or assigned a floating-point environment macro, such as FE_DFL_ENV.


See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <fenv.h>
#include <stdio.h>
#include <assert.h>

int main(void)
  int nonStopFail;
  fenv_t envp;
  volatile double x, y=1E30;

  nonStopFail = feholdexcept(&envp);        // save the current environment
  assert(nonStopFail == 0);
  x = 1 / y;
  printf("the small result rounded up is %g\n", x);
  x = 1 / y;
  printf("the small result rounded down is %g\n", x);
  feupdateenv(&envp);                       // restore the environment

Example Output

The small result rounded up is 1.00001e-30
The small result rounded down is 9.99999e-31