Background
I have a program which sometimes throws floating point exceptions due (primarily) to divide by zero despite having checks in place for dividing by zero values. This could be related to floating point speculation but I'm not sure.
I have implemented a handler for FPEs using feenableexcept
/SIGFPE
but this merely stops my program dead, which is better than propagating NaN
s throughout the data.
I found this old page which talks about floating point traps, and seems to suggest that such a trap is responsible for the default behavior of returning NaN
,Inf
or -Inf
on dividing by zero. This got me thinking.
Question
Is it possible to somehow have a division by zero always return the value 0.0
? (One might wonder about the validity of this but in my case this is desirable)
Details
I am using intel compilers version 13.0.0 (gcc version 4.4.7 compatibility) on linux.