|
-
July 5th, 1999, 09:31 AM
#1
Division by zero
Is that true that VC++ 6.0 compilator doesn't mind if I divide something by zero, or I've missed something? The following code works:
double a;
double b;
a = 10;
b = 0;
try
{
a = a / b;
}
catch (...)
{
// some code.
}
Division by zero wasn't even catched.
-
July 5th, 1999, 10:46 AM
#2
Re: Division by zero
In is not the job of the compiler to detect such things.
-
July 5th, 1999, 11:13 AM
#3
Re: Division by zero
According to the C++ Standard (5.5), if the result is not mathematically defined, or not in the range of representable values, the result is undefined (so the compiler can do anything). In the case of divide by zero and floating point exceptions, treatment of the result varies among machines, and may be adjustable via a library routine.
With floating-point arithmetic with VC++ on Intel PCs, division by zero gives a result value in 'a' of infinity, which is represented as 1.#INF. Integer types (e.g. int) will cause an exception to be thrown.
Dave
-
July 5th, 1999, 11:18 AM
#4
Re: Division by zero
You're right, of course, but I think he really meant the VC++ run-time code...
Whatever :-)
Dave
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|