fegetenv Function

Stores the floating-point environment into an object.

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




void fegetenv(fenv_t * envp);


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


This function gets the current floating-point environment and stores it into the object pointed to by the pointer argument.


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