The LN() function in MySQL is used to return the natural logarithm (logarithm to the base e) of a number.
Syntax
LN(number)
Definition and Usage
- The
LN()function computes the natural logarithm of the given number. - The natural logarithm is the logarithm to the base e, where
eis approximately2.71828. - The argument must be greater than 0. If the argument is less than or equal to 0, it returns
NULL.
Parameter Values
| Parameter | Description |
|---|---|
number |
Required. A positive numeric value to compute the natural logarithm of. |
Technical Details
- Works in: From MySQL 4.0
- Return Value: The natural logarithm of the number (a floating-point value).
Examples
Example 1: Return the natural logarithm of 2
SELECT LN(2);
Result:
LN(2): 0.693147
Explanation: The natural logarithm of 2 is approximately 0.693147.
Example 2: Return the natural logarithm of 1
SELECT LN(1);
Result:
LN(1): 0
Explanation: The natural logarithm of 1 is always 0, as e^0 = 1.
Example 3: Return the natural logarithm of a number greater than 1
SELECT LN(10);
Result:
LN(10): 2.302585
Explanation: The natural logarithm of 10 is approximately 2.302585.
Related Functions
LOG(): Computes the logarithm of a number to a specified base. If no base is provided, it defaults to the natural logarithm (same asLN()).EXP(): Computeseraised to the power of the given number.
Usage Notes
- The
LN()function is most commonly used in calculations involving growth, decay, and continuous compounding, as the natural logarithm is frequently used in calculus and mathematics. - The argument must always be greater than 0, as logarithms of non-positive numbers are undefined in real numbers.