log (JavaScript)
Gets the natural logarithm (base e) of a number.
Defined in
Math (JavaScript)Syntax
log(value:double)
: double
Parameter | Description |
---|---|
value |
A positive number. See below for special cases. |
Return value | Description |
---|---|
double |
The natural logarithm of the parameter. |
Usage
Special cases are as follows:- The logarithm of
NaN
or a number less than 0 is NaN. - The logarithm of
+Infinity
is positive infinity. - The logarithm of 0 or -0 is negative infinity.
See exp (JavaScript) for the inverse to this method.
To get the logarithm to the base 10 of a number, multiply the return value of this method by LOG10E (JavaScript).
To get the logarithm to the base 2 of a number, multiply the return value of this method by LOG2E (JavaScript).
Examples
(1) This buttononclick
event
calculates the cube root of a number.sessionScope.result =
Math.exp(Math.log(sessionScope.n) / 3)
(2) This button
onclick
event
gets the logarithm of a number to the base 10.sessionScope.log10 = Math.log(sessionScope.n) * Math.LOG10E
(3)
This button
onclick
event gets the logarithm of a
number to the base 2.sessionScope.log2 = Math.log(sessionScope.n) * Math.LOG2E