Math.log( x ) in ECMAScript 262
Return the natural logarithm of x
.
Arguments
name | type | description |
---|---|---|
x | Number | The value to operate upon. |
- Return Type
- Number
Description
This function returns the natural logarithm of the argument; i.e. the log-base-e. Put another way, Math.pow(Math.E , Math.log( n ) ) == n
. (Or more simply, Math.exp( Math.log(n) ) == n
.)
To get the log-base-10 value of a number, use the fact that log-base-t( x ) == log-base-e(x) / log-base-e(t)
.
The following code will provide the Math
class with a new convenience function for log-base-10:
Math.log10=function(x){ return Math.log(x)/Math.LN10 }
Or, for a more general case:
Math.logN=function(n,x){ return Math.log(x)/Math.log(n) }