6.5.16 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 when using a device with a FPU.

Include

<fenv.h>

Prototype

void feupdateenv(fenv_t * envp);

Argument

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

Remarks

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.

Example

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);
  fesetround(FE_UPWARD);
  x = 1 / y;
  printf("the small result rounded up is %g\n", x);
  fesetround(FE_DOWNWARD);
  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