I'm trying to catch a floating point zero divide exception, but it doesn't seem to be working out and I can't figure out why the (minimal) code I have right now is:
So that when I enter something like: 12.2 0.0 or 0 0 the signal isn't caught/triggered, however, when I changed it to read in two integers and divide them, it was caught.Code:#include <stdio.h>
#include <signal.h>
#include <unistd.h>
void handle_zero(int sig_num){
printf("caught zero divide");
}
int main(){
float num1,num2;
signal(SIGFPE,handle_zero);
while (42){
printf("divide: ");
scanf("%f %f", &num1, &num2);
printf("result: %f\n",num1/num2);
}
return 0;
}
So what's the proper signal for floating point, or what am I doing wrong?
Thanks.