Thread: divide by zero

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    divide by zero

    Hello everyone,


    I have verified that the result of 100/0 will not occur any exception, and it will be infinite.

    Does it mean there is no exceptions like divide by zero in C#?


    thanks in advance,
    George

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Seems like it.

    It may be something you can define yourself tho'.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    100 / 0 throws a DivideByZero exception
    100.0 / 0.0 does not throw an exception and the result will be Inf
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats and Magos,


    I have tried as well. Seems the conclusion is, int/decimal will occur divide by zero exception, but float/double will not?

    Quote Originally Posted by Magos View Post
    100 / 0 throws a DivideByZero exception
    100.0 / 0.0 does not throw an exception and the result will be Inf

    regards,
    George

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Thats what happens when Microsoft invents a language. Though jabbing ms aside, they probably did that to lower instances of run-time errors. Though, that is one you'd want to know about, as the developer.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks master5001,


    Agree with my points in post #4? :-)

    Quote Originally Posted by master5001 View Post
    Thats what happens when Microsoft invents a language. Though jabbing ms aside, they probably did that to lower instances of run-time errors. Though, that is one you'd want to know about, as the developer.

    regards,
    George

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yeah I do agree with you. I just couldn't imagine how a company that develops software would consider that a useful characteristic for other developers. Who knows. Good find though. I don't use C# as often as C/C++/VB, but I will keep that in mind. Though now I am going to have to do some tests with VB, chances are it does the same.

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks for your clarification, master5001!


    Quote Originally Posted by master5001 View Post
    Yeah I do agree with you. I just couldn't imagine how a company that develops software would consider that a useful characteristic for other developers. Who knows. Good find though. I don't use C# as often as C/C++/VB, but I will keep that in mind. Though now I am going to have to do some tests with VB, chances are it does the same.

    regards,
    George

  9. #9
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Wow, you're constantly posting the same questions on many boards (Cprogramming.com, MSDN forums, Wizard Scripts, CodeGuru.com, Devarticles.com and probably many more). Are you a bot or something? ^^
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Magos View Post
    Wow, you're constantly posting the same questions on many boards (Cprogramming.com, MSDN forums, Wizard Scripts, CodeGuru.com, Devarticles.com and probably many more). Are you a bot or something? ^^
    Yes, George2 does that. It's a bit annoying at times.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Registered User
    Join Date
    Apr 2008
    Location
    USA
    Posts
    24

    George2

    George2 could merely be looking for consistency in the responses received for a given post. Boards systems have come along way with the growing knowledgability of a more informed programming society, but we still have a ways to go. Allot of times you have to, still yet, piece mill a solution together and inevitably debug the holy hell out of it to get it up to snuff, but it is getting better all the time because of members like you all.

    The divide by zero appears to be a .Net Framework problem in scope. This scenario involves all .Net languages to include C# and VB.Net to name a short few. The VS .Net executables and .dll's are assembly sets that act as 'assembly instructions' that are parsed and then sent to the .Net JIT compiler for creation.

    Basically a .Net assembly acts as a Make and Linker file all in one and it is with this all in one file that the JIT compiles and links your system into bytecode and dynamically stored into memory for operations.

    The divide by zero will have to be handled with managed code from within your system's internal code with a specially designed try - catch method as previously stated. The reasoning behind the managed handling was that the .Net Framework has to be a common interface for any language that wants to use it and not all programming languages handle divide by zero equally. This method of handling the divide by zero fault eliminates allot of overiding and system clashes for the time being.

    I personally think that a nominal divide by zero try-catch error handling system should be present, if it isn't already and we are merely overlooking it somehow, and to avoid system clashes between languages you must declare the default as being used for DB0 or you must define it yourself with managed code. This would eliminate allot of confusion.

  12. #12
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks TheRaven,


    1.

    Quote Originally Posted by TheRaven View Post
    Basically a .Net assembly acts as a Make and Linker file all in one and it is with this all in one file that the JIT compiles and links your system into bytecode and dynamically stored into memory for operations.
    I am interested why you call a .Net assembly "a Make and Linker file all in one"? :-)

    2.

    Quote Originally Posted by TheRaven View Post
    I personally think that a nominal divide by zero try-catch error handling system should be present, if it isn't already and we are merely overlooking it somehow, and to avoid system clashes between languages you must declare the default as being used for DB0 or you must define it yourself with managed code. This would eliminate allot of confusion.
    What means DB0?


    regards,
    George

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by George2 View Post
    What means DB0?
    Presumably, Divide By 0 (that last bit is a zero, not an O).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Quote Originally Posted by George2 View Post
    I have tried as well. Seems the conclusion is, int/decimal will occur divide by zero exception, but float/double will not?
    That's because floating-point numbers have special values for Infinity and NaN (Not a Number). It just sets the result to Inf if there is division by zero (though I'd argue from a mathematical point of view, NaN would be more appropriate as the result of such a division is undefined).
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  15. #15
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats and Cat,


    Any comments to my question item 1 in post #12?

    Quote Originally Posted by Cat View Post
    That's because floating-point numbers have special values for Infinity and NaN (Not a Number). It just sets the result to Inf if there is division by zero (though I'd argue from a mathematical point of view, NaN would be more appropriate as the result of such a division is undefined).

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 01-24-2008, 09:40 PM
  2. Divide 64bit number
    By freeindy in forum C Programming
    Replies: 4
    Last Post: 10-01-2007, 03:56 AM
  3. Divide and Conquer: array in the reverse order
    By Steamer in forum C Programming
    Replies: 11
    Last Post: 03-08-2004, 07:31 PM
  4. severe beating of divide by zero
    By muttski in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 11-22-2002, 05:54 PM
  5. Divide and Average Algorithm
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 01-25-2002, 03:30 PM