April 25th, 2003, 12:45 PM

[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 12:54 PM.
April 25th, 2003, 12:56 PM

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 :)
April 25th, 2003, 01:20 PM

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.
April 25th, 2003, 01:23 PM

April 26th, 2003, 04:44 PM

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)
PHP is fun
April 26th, 2003, 05:17 PM

woops sorry. i guess the page didn't update because i thought it didn't post lol.
PHP is fun
April 27th, 2003, 08:18 PM

i don't deny there's a few holes in my maths knowledge :)