Pseudocode algorithm for doing a logarithm.
Assuming we want log_n of x
result = 0;
base = n;
input = x;
while (input > base)
result++;
input /= base;
fraction = 1/2;
input *= input;
while (((result + fraction) > result) && (input > 1))
if (input > base)
input /= base;
result += fraction;
input *= input;
fraction /= 2.0;
The big while loop may seem a bit confusing.
On each pass, you can either square your input or you can take the square root of your base; either way, you must divide your fraction by 2. I find squaring the input, and leaving the base alone, to be more accurate.
If the input goes to 1, we're through. The log of 1, for any base, is 0, which means we don't need to add any more.
if (result + fraction) is not greater than result, then we've hit the limits of precision for our numbering system. We can stop.
Obviously, if you're working with a system which has arbitrarily many digits of precision, you will want to put something else in there to limit the loop.