I read this and this. The quintessence is that one can throw a SIGFPE if a nan is produced by including fenv.h and enabling all floating point exceptions but FE_INEXACT
by feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT);
Thus, the code changes form
int main () {
double dirty = 0.0;
double nanvalue = 0.0/dirty;
return 0;
}
to
#include <fenv.h>
int main () {
feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT); // Enable all floating point exceptions but FE_INEXACT
double dirty = 0.0;
double nanvalue = 0.0/dirty;
return 0;
}
This works fine, but you have to change the code. I have the problem, that in a huge c and c++ code base, somewhere a nan is produced and I don't know where. It is not an option to apply the above change to hunderts of files and track the error.
Is there a way to enable the all floating point exceptions, WITHOUT a code change? Is there a compile option I am not aware of?
We use the intel icc version 15.0.3 compiler.
No matter how many files your code spans, you only need to add feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT)
once only, at the first line of your main()
function.
It will enable the exceptions for your whole program until you disable the exceptions by calling another function such as fedisableexcept()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With