Slashdot Mirror


Ask Slashdot: What's the Harm In a Default Setting For Div By Zero?

New submitter CodeInspired writes: After 20 years of programming, I've decided I'm tired of checking for div by zero. Would there be any serious harm in allowing a system wide setting that said div by zero simply equals zero? Maybe it exists already, not sure. But I run into it all the time in every language I've worked with. Does anyone want their div by zero errors to result in anything other than zero?

2 of 1,067 comments (clear)

  1. Re:Infinity by lenart · · Score: 5, Informative

    Mathematically, the result is undefined. So neither is correct. Nor is anything inbetween.

  2. Re:Infinity by vux984 · · Score: 5, Informative

    When you have 0/0, you hit two "obvious" but contradictory rules in basic algebra:

    Rule one: anything multiplied by zero is zero
    Rule two: anything divided by itself is one

    Ugh no, just no.
    "Rule one: anything multiplied by zero is zero"

    Yes, this is called, amongst other things, the zero property of multiplication. However 0/0 is not a multiplication and the rule is not relevant, and there is no conflict.

    Secondly your "rule two" is not actually rule of algebra. There is no rule x/x = 1.

    There is an identity rule for division: anything divided by one is itself (x/1 = x) but there is no rule that says x/x = 1

    You can derive "rule two" from the identity rule for multiplication x*1 = x --> x/x = 1

    However, that transformation always stipulates that x 0 because division by zero is undefined.

    Mathematicians have no issue determine which rule has precedence, because neither rule applies to 0/0.
    There is no conflict. Division by zero is specifically "undefined".

    Consider the equation; x/x.

    http://www.wolframalpha.com/in...

    The graph of the function is a horizontal line at y=1, with a discontinuity at 0. (if x=0, x/x=0/0) So 0/0 should be 1 right? Because everywhere else on the graph x/x = 1??

    http://www.wolframalpha.com/in...

    Now consider the equation 2x/x.

    http://www.wolframalpha.com/in...

    As x approaches 0 (lim x->0) from either the left or right the limit of the equation is 2. A graph of the function is horizontal line at y=2, with a discontinuity at 0. But every where else 2x/x = 2. So shouldn't 2(0)/0 = 0/0 = 2? So 0/0 should be 2 right?

    http://www.wolframalpha.com/in...

    Neither. Its not defined.

    Now consider the equation 1/x.

    http://www.wolframalpha.com/in...

    As x approaches 0 from the left it goes to negative infinity. As x approaches 0 from the right it goes to positive infinity. This graph doesn't even suggest a value for 0/0? Is it + infinity? Or - infinity?

    I can write a function that makes 0/0 look like it should be anything I want.
    0/0 is undefined. It doesn't violate any rules of algebra. It's a rule of algebra that division by 0 is undefined.