fesetenv Function

Establishes the floating-point environment from an object.

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




void fesetenv(fenv_t * envp);


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


This function establishes the floating-point environment from the object pointed to by envp. This pointer 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. Although the state of the floating-point status flags are set, these floating-point exceptions are not raised.


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>

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

  fegetenv(&envp);              // save the current environment
  fesetround(FE_UPWARD);        // change the environment
  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);
  fesetenv(&envp);              // restore the environemnt

Example Output

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