Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
98
rated 0 times [  103] [ 5]  / answers: 1 / hits: 80105  / 14 Years ago, thu, june 10, 2010, 12:00:00

I need a log function for JavaScript, but it needs to be base 10. I can't see any listing for this, so I'm assuming it's not possible. Are there any math wizards out there who know a solution for this?


More From » math

 Answers
243

Change of Base Formula / Identity




The numerical value for logarithm to the base 10 can be calculated
with the following identity.




Logarithm






Since Math.log(x) in JavaScript returns the natural logarithm of x (same as ln(x)), for base 10 you can divide by Math.log(10) (same as ln(10)):



function log10(val) {
return Math.log(val) / Math.LN10;
}


Math.LN10 is a built-in precomputed constant for Math.log(10), so this function is essentially identical to:



function log10(val) {
return Math.log(val) / Math.log(10);
}

[#96535] Tuesday, June 8, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brandt

Total Points: 43
Total Questions: 90
Total Answers: 111

Location: Aruba
Member since Fri, Jun 24, 2022
2 Years ago
;