Basically like the opposite of Math.pow().
I want a function which can be used as such a logarithm:
var mynum = findpower(36, 6); // 2, because 6 squared is 36
How could such a function be constructed?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a logarithm
in general case
The logarithm has following property: if a = log(n = number, b = base) (usually denoted as logb(n)) then ba = n. In my code above I used logarithms property: logy(x) = logc(x) / logc(y) where c is any positive number.
Math.login examples above is the natural logarithm, i.e. the logarithm with base = e (≈ 2.718281828…, see Math.E). Obviously, if we have the natural logarithm (usually denoted as ln(n) or log(n)), then we have the logarithm with any other base via the equation given above: logy(x) = log(x) / log(y)