6.5.8 fegetexceptflag Function
Stores the floating-point exception flags represented by the argument excepts 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 fegetexceptflag(fexcept_t * flagp, int excepts);
Arguments
flagp
- a pointer to the object in which the flag representation will be stored
excepts
- a value being the bitwise OR of one or more floating-point exception macros, representing the exceptions to store
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