# Retrieve the logarithm of number in a specified base ?

A Person definitely_not at aol.com
Sun Dec 5 17:53:31 CET 2004

```To retrieve the logarithm of a number in a specified base, you'll need to make
a radix change from base 10 to the number base.

Here's an example: (we use base 3 and want the logorithm of 111)

3^x = 111
log(3^x) = log(111)
x*log(3) = log(111)
x = log(111)/log(3)

log could be either natural log or log10.

using approximations
log(111) =  4.709530201312334135763340908
log(3) = 1.098612288668109691395245237

x = 4.709530201312334135763340908/1.098612288668109691395245237
x = 4.286799128218272844528773667

Now you have to convert from base 10 to base 3

Convert the integer part to base 3
4 = 11

Convert the fraction part to base 3 which is done by multiplying
and keeping track of when the fraction equals or exceeds 1 and
subtracting this amount (1 <= number < base) and continuing.
Usually the fraction will not disappear, so we can find this to
the accuracy of our previous computation.

However for each step we keep track of the integer part and write
it down, as this is our fraction in base 3

3*0.286799128218272844528773667 = 0.8603973846548185335863210007
so 0 is the first fractional part

3*0.8603973846548185335863210007 = 2.581192153964455600758963002
so 2 is the next fractional digit
we subtract 2

3*0.5811921539644556007589630022 = 1.743576461893366802276889007
so 1 is the next digit

and so on, and we gradually obtain

11.02120200200121100011111021120112022022020012001121012212100 as
our logarithm in base 3

This could easily be incorporated in gmp if it doesn't already exist.
Like you, I've just responded off the top of my head and haven't read
the {censored_word} manual yet.

```