fesetexceptflag Function

Sets the floating-point status flags to those represented by the state stored in the object.

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

Include

<fenv.h>

Prototype

void fesetexceptflag(fexcept_t * flagp, int excepts);

Arguments

flagp
a pointer to the object from which the flag representation will be read
excepts
a value being the bitwise OR of one or more floating-point exception macros, representing the possible exceptions to set

Remarks

The pointer must hold an address obtained by a previous call to fegetexceptflag() whose second argument represented at least those floating-point exceptions being set by this call. Only those state flags in the second argument may be set by this function. This function does not raise floating-point exceptions; it only sets the state of the flags.

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 <math.h>

void showExceptions(void)
{
  printf("Exceptions currently raised: ");
  if(fetestexcept(FE_DIVBYZERO))
    printf("FE_DIVBYZERO ");
  if(fetestexcept(FE_INEXACT))
    printf("FE_INEXACT ");
  if(fetestexcept(FE_INVALID))
    printf("FE_INVALID ");
  if(fetestexcept(FE_OVERFLOW))
    printf("FE_OVERFLOW ");
  if(fetestexcept(FE_UNDERFLOW))
    printf("FE_UNDERFLOW ");
  printf("\n");
}

volatile double result = 0.0;

int main(void)
{
  fexcept_t excepts;

  result = 1.0 / result;                       // raise FE_DIVBYZERO
  showExceptions();
  fegetexceptflag(&excepts, FE_ALL_EXCEPT);    // save state
  feraiseexcept(FE_INVALID|FE_OVERFLOW);       // raise exceptions without operation
  showExceptions();
  fesetexceptflag(&excepts, FE_ALL_EXCEPT);    // restore state
  showExceptions();
}

Example Output

Exceptions currently raised: FE_DIVBYZERO 
Exceptions currently raised: FE_DIVBYZERO FE_INEXACT FE_INVALID FE_OVERFLOW 
Exceptions currently raised: FE_DIVBYZERO