```
#include <fenv.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
static void fpe_handler(int sig, sig)info_t *info, void *uap)
{
printf("Caught signal %d\n", sig);
printf("si_signo %d\n", info->si_signo);
printf("si_code %d\n", info->si_code);
printf("si_addr 0x%x\n", (unsigned int)info->si_addr);
if (info->si_signo == SIGFPE &&
info->si_code == FPE_FLTDIV) {
printf("Caught SIGFPE due to FPE_FLTDIV, as expected\n");
} else
printf("Caught unexpected signal.\n");
}
int main(void)
{
struct sigaction sa;
volatile double x,y, res; sa.sa_sigaction = handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO; /* Restart functions if
interrupted by handler */
if (sigaction(SIGFPE, &sa, NULL) == -1)
{
printf("error\n");
}
int mask = feenableexcept(FE_INVALID |
FE_DIVBYZERO |
FE_OVERFLOW |
FE_UNDERFLOW);
signal(SIGFPE, fpe_handler);
printf("mask: %x\n", mask);
double x = 0.0;
double y = 1234.0 ;.0 / x;
res = y / x; printf("y = %f\n", y);
return res;
}```y;
}
```