# Question about the terms and operations in basic division

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?

-

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.
@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