6.5.7 fegetenv Function

Stores the floating-point environment into an object.

Attention: This function is implemented only by MPLAB XC32 C compilers when using a device with a FPU.

Include

<fenv.h>

Prototype

void fegetenv(fenv_t * envp);

Argument

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

Remarks

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

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>

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);
  fesetround(FE_DOWNWARD);
  x = 1 / y;
  printf("The small result rounded down is %g\n", x);
  fesetenv(&envp);              // restore the environment
}

Example Output

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