feholdexcept Function

Stores the floating-point environment into an object then installs a non-stop exception mode.

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




int feholdexcept(fenv_t * envp);


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

Return Value

This function returns zero if and only if the non-stop exception mode was successfully installed.


This function saves the current floating-point environment in the object pointed to by envp, clears the floating-point status flags, and then installs a non-stop exception mode, if available. Once installed, the non-stop mode will allow execution to continue on a floating-point exception and can be used to hide spurious floating-point exceptions.


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