#include <fenv.h>
int main(void)
{
feenableexcept(FE_ALL_EXCEPT);
double x = 0.0;
double y = 1.0 / x;
return 0;
}
With sigaction:
#include <fenv.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
static void handler(int sig)
{
printf("Caught signal %d\n", sig);
}
int main(void)
{
struct sigaction sa;
sa.sa_handler = handler;
Sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
if (sigaction(SIGFPE, &sa, NULL) == -1)
{
printf("error\n");
}
feenableexcept(FE_ALL_EXCEPT);
double x = 0.0;
double y = 1.0 / x;
return y;
}