CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    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.


  2. #2
    Join Date
    Jun 1999
    Posts
    16

    Re: Division by zero

    In is not the job of the compiler to detect such things.


  3. #3
    Join Date
    Apr 1999
    Posts
    383

    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


  4. #4
    Join Date
    Apr 1999
    Posts
    383

    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
  •  





Click Here to Expand Forum to Full Width

Featured