### Thread: [c] calculating logs using a variable base number?

1. No Profile Picture
.
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2002
Posts
296
Rep Power
12

#### [c] calculating logs using a variable base number?

is there a math function in c to calculate a log using a variable base number?

i can see log2 and log which is base 10, but what happens if you want other than base 10 or 2?

edit: oh, i've just found out log is not base 10. it calculates the natural logarithm of the given number (which uses e right?). log10 is the base10 version of log that uses base 10
Last edited by balance; April 25th, 2003 at 11:54 AM.
2. No Profile Picture
Contributing User
Devshed God 1st Plane (5500 - 5999 posts)

Join Date
Oct 2000
Location
Back in the real world.
Posts
5,966
Rep Power
190
Code:
`blog(n)=clog(n) / clog(b)`
For any c>0 (not sure about the exact bounds for c). i.e. you can use either log10() or log() for the both :)
3. No Profile Picture
.
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2002
Posts
296
Rep Power
12
you confused me for a second there with your blogs'n'clogs (yes i did man blog and man clog :) ) , but i see what you mean now. got it. thanks.
4. No Profile Picture
Contributing User
Devshed God 1st Plane (5500 - 5999 posts)

Join Date
Oct 2000
Location
Back in the real world.
Posts
5,966
Rep Power
190
5. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2002
Posts
56
Rep Power
13
they really should have taught you proper log functions in school.

lets say i have 5^x and it equals 25 (5^2 = 25). we right that as
log5 25, correct?
to calculate that, use the log of the big number / log of small number. you put it into your calculator like this:
log(25) / log(5)
if your calculator works properly, it will tell you the answer is 2 :D

just remember ----> big number over little number (big as in how big you write it, not the value)
6. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2002
Posts
56
Rep Power
13
woops sorry. i guess the page didn't update because i thought it didn't post lol.
7. No Profile Picture
.
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2002
Posts
296
Rep Power
12
i don't deny there's a few holes in my maths knowledge :)