views:

77

answers:

3

I'm having a mental block here, and algebra not really being my thing, can you tell me how to re-write the JavaScript code below to derive the variable, c, in terms of a and b?:

a = Math.pow(b, c);
c = ?

Thanks!

+3  A: 

Logarithms. You want the logarithm of a. B is the base, c is the exponent, so

logb a = c

Charlie Martin
Logs! Of course. Thanks, Charlie.
Premasagar
+6  A: 
c = Math.log(a)/Math.log(b)
dusan
http://en.wikipedia.org/wiki/Logarithm
Spot on. Thanks!
Premasagar
A: 

A logarithm is the inverse of an exponent, you can do, for example:

>>> x = math.pow(2,5)
>>> print x
32.0
>>> math.log(x, 2)
5.0
vezult
Cheers Vezult...
Premasagar