I have included validation for nan in my testuite.
SIGFPE is now thrown on the next line
const double retVal =exp(exponent);
The indicator has a value of approximately 4000. This, of course, is very close to zero and without nan-verification, the calculation continues with zero.
The SIGFPE signal is now thrown. I assume this is a denormal number (represented as NAN).
How can I distinguish between division by zero and exponent with a very large negative value?
In the second case, further calculations with zero work in my case, since I do not need to distinguish between +0 and -0.
EDIT: I tried what @ user2079303 suggested. My code is as follows:
#include <signal.h>
void fpe_handler(int signo, siginfo_t *info, void *context) {
switch(info->si_code) {
case FPE_INTDIV:
break;
case FPE_FLTUND:
break;
}
}
int main() {
struct sigaction action = {};
action.sa_flags = SA_SIGINFO;
action.sa_sigaction = fpe_handler;
sigaction(SIGFPE, &action, NULL);
const double a = 0.0/0.0;
if (a>0)
return 0;
else
return 1;
}
, .