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?
Burning karma here to see if anyone else has the same problem. Mod offtopic if you like.
New posts of mine aren't showing up for about half an hour typically. Do they need to be staff approved now or something?
Second, on several front page stories, I no longer have the option to post. They say, "Nothing to see here. Move along" and "Archived discussion".
I think the new design changes are pretty alright, but those two are breaking changes for me.
I won't mention names to hopefully dodge any lawyers lurking about, but "a friend" works in the airline industry and a certain commercial aircraft flight computer on receiving bad or missing data from the Inertial Reference System would happily go on reporting a value without indicating an error. Luckily, this friend became aware of the problem trying to resolve a CG issue before takeoff. Fun times.
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
Mathematicians don't know which rule has precedence for 0/0, so there's no way a dumb machine can figure it out, which is why most programing languages just throw an exception if zero is the denominator.
If it works, it's obsolete
Mathematically, the result is undefined. So neither is correct. Nor is anything inbetween.
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
Mathematicians don't know which rule has precedence for 0/0, so there's no way a dumb machine can figure it out, which is why most programing languages just throw an exception if zero is the denominator.
It's mathematically possible to do some form of 0/0 using limits and the calculus.
lim x->0 x/x = 1
Also lets you do some interesting other things, like:
lim x->0 x^2/x = 2
lim x->0 sin(x) / x = 1
Shouldn't be too hard to get a function that gives you the correct "approximate" value of the function near the indeterminate point, if there is one. It's just a bunch of special cases that you have to check for every time you do an operation that might possibly result in a div/0 error, right? Go ahead. DO IT! I'll wait.
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.