Set flag for SIGFPE and continue execution ignoring FPEs

view story

http://stackoverflow.com – In a numerical application, I'd like to know if a floating point exception occured after the computation finishes. By default, floating point divisions and invalid operations are ignored silently. My attempt is to enable FPEs I care about, handle SIGFPE by setting a flag and disabling them again to allow execution to continue: #include <fenv.h> #include <signal.h> #include <stdio.h> int caught = 0; struct sigaction old_sa; /* (2) */ fenv_t fenv_hold; void sighandler() { caught = 1; printf("Caught in handler, disabling\n"); /* (1) */ fedisableexcept(FE_ALL_EXCE (HowTos)