Should divide by zero cause an exception with floating point exceptions enabled?

  • Thread starter Thread starter SmacL
  • Start date Start date
S

SmacL

Guest
I've been debugging a C++ application in VS2015 and found that a number of my double variables were ending up a NaN following a divide by zero. While this is reasonable, I have floating point exceptions enabled (/fp:except) so I would have expected this to raise an exception. Looking at the MS help page, it doesn't list what causes a floating point exception. According to this answer to a related question, divide by zero is a floating point exception. This is not the case, i.e. the following test program with /fp:except enabled

int main()
{
try
{
double x = 1;
double y = 0;
double z = x / y;
printf(
"%f\n", z);
return 0;
}
catch (...)
{
printf(
"Exception!\n");
return 0;
}
}


displays "inf". Should this raise a floating point exception?

Edit: Checked the exceptions were enabled in the debugger and get the same result regardless x1ZAh.jpg

Edit2: Further reading here on IEE 754 suggests to me that with floating point exceptions enabled I should be getting an exception. A comment to the previously linked question however states 'The name "floating point exception" is a historical misnomer. Floating point division by zero is well-defined (per Annex F/IEEE754) and does not produce any signal.'

Continue reading...
 
Back
Top