Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Let's pretend that I am a child and you want to teach me division. You demonstrate through an example division as repeated subtraction.

This is the simple algorithm the child learns from your lesson:

n=0
remainder=dividend
if(dividend == divisor) return 1;
while(remainder > divisor) {
  n = n + 1;
  remainder=remainder - divisor; 
}
println "Whole portion: ", n, " with remainder ", remainder, "/", divisor

There is a bug in that algorithm. See if you can spot it.

Here is the revised version:

n=0
remainder=dividend
assert(divisor != 0);
if(dividend == divisor) return 1;
while(remainder > divisor) {
  n = n + 1;
  remainder=remainder - divisor; 
}
println "Whole portion: ", n, " with remainder ", remainder, "/", divisor

In this version if you try to divide by zero, the system fails.

There is a different way to fix the bug though. The bug was an infinite loop, btw, if you didn't notice, because remainder would never decrease when the divisor was zero.

n=0
remainder=dividend
if(dividend == divisor) return 1;
while( (n==0 && n>divisor) && remainder > divisor) {
  n = n + 1; 
  remainder=remainder - divisor; 
}
println "Whole portion: ", n, " with remainder ", remainder, "/", divisor

So for example, if you divide 3/8 you get:

Whole portion: 0 with remainder 3/8

If you try to divide 3/0 you get:

Whole portion: 0 and 3/0 remaining.  

What am I doing wrong in the third example? Isn't dividing by zero asking for a fractional number < 0?

Isn't that just a special kind of complex number?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Division by zero is undefined and the result of the operation is not a number, neither real nor complex.

Division by zero can sometimes be represented by limits, e.g. $$ \lim_{x \to 0} 1/x^2 = +\infty, \text{ but } \lim_{x \to 0^+} 1/x = +\infty \text{ while } \lim_{x \to 0^-} 1/x = -\infty, $$ so the 2-sided limit would be undefined in the latter case.

share|improve this answer
    
So the response could be NaN instead of an assertion? –  Justin Swanhart Jul 4 '13 at 6:14
1  
@JustinSwanhart NaN is from programming :) and indeed the IEEE floating standard defines $x/0$ as Inf for $x>0$ or -Inf for $x<0$ or NaN for $x=0$. –  gt6989b Jul 4 '13 at 21:26
    
I'm developing a system that can store and do math like humans do, so I'm making sure everything works using the simplest algorithms possible before optimizing. This is also helping me relearn my basic math skills. I am also using a base 2^32 abacus internally. If you think humans are fast with a base10 abacus you should see a computer with a base 2^32 one. –  Justin Swanhart Jul 5 '13 at 5:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.