Inconsistent results from divide-by-zero

  • Thread starter Thread starter Bob Altman
  • Start date Start date
B

Bob Altman

Hi all,

We have some native C++ code that (inadvertently) performs a divide-by-zero
operation. This code is baked into two different executables, both built by
VS 2005. In one case, the divide-by-zero produces a result of positive
infinity (the debugger displays the value of the variable on the left side
of the equal sign as "#IND00"). In the other case, the divide-by-zero
results in a runtime exception.

We've looked through the project properties for some setting that might turn
divide-by-zero exceptions into "infinity" results, but the closest thing we
can find is /fp:except (which is disabled in both projects, and which would
only have the effect - if I understand it correctly - of deferring the
divide-by-zero exception until the next floating point operation).

Can someone give me a clue as to why the two projects behave differently?

TIA - Bob
 
Can someone give me a clue as to why the two projects behave differently?

Do either of the projects make use of _control87, _controlfp, or
__control87_2 ?

Dave
 
David Lowndes said:
Do either of the projects make use of _control87, _controlfp, or
__control87_2 ?

That sounds promising, but, no, none of the projects use that stuff.
 
Do either of the projects make use of _control87, _controlfp, or
That sounds promising, but, no, none of the projects use that stuff.

Is it possible that one of the projects pulls in some static library
or DLL component that may use those facilities?

Dave
 
David, thanks for your valuable input.

Hello Bob,

Thanks for using Microsoft Newsgroup Support Service, my name is Rongchun
Zhang[MSFT] and I will work on this issue with you.

Based on my understanding, division by zero can be divide into two types:
floating point and integer. Floating point division by zero has a
well-defined result. In IEEE 754 arithmetic, a ¡Â 0 is positive infinity
when a is positive, negative infinity when a is negative, and NaN (not a
number) when a = 0. However, integer division by zero is usually handled
differently from floating point since there is no integer representation
for the result. Usually, it generates an exception when attempting to
divide an integer by zero. More information, please check:

http://en.wikipedia.org/wiki/Division_by_zero

Since I don't know how your code works, I would like to suggest that you
check if it is a floating point division or an integer division.

Also, Windows NT has all floating point exceptions (see
http://msdn.microsoft.com/en-us/library/aa226618(VS.60).aspx) turned off by
default. However, the floating-point control state can be changed (as David
pointed out, it might be enabled by other dll). The following KB show you
how to enable all floating point exception.

http://support.microsoft.com/kb/94998

I suggest you try to disable the division by zero exception first in your
code and see if the run time error still happens.

int cw = _control87( 0,0 );
cw |= EM_ZERODIVIDE;
_control87( cw, MCW_EM );

Let me know if this helps. If not, it would be helpful if you can provide
more detailed information about your code and projects, so that we can
investigate the issue locally. It is not necessary that you send out the
whole of your project. We just need a simplest sample to reproduce the
problem. You can remove any confidential information or business details
from it. I appreciate your work on providing these information.

If you have any additional questions and concerns, feel free to contact me.

Best regards,
Rongchun Zhang ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top