All Products
Search
Document Center

MaxCompute:LN

Last Updated:Mar 26, 2026

Returns the natural logarithm (base e) of number.

Syntax

double|decimal ln(<number>)

Parameters

number: Required. A value of the DOUBLE or DECIMAL type. STRING and BIGINT inputs are implicitly converted to DOUBLE before calculation.

Return value

Input typeReturn type
DOUBLEDOUBLE
DECIMALDECIMAL
STRING or BIGINTDOUBLE
Negative number or 0NULL
NULLNULL

Examples

Static values

-- Returns 0.0
SELECT ln(1);

-- Returns 1.144729868791239
SELECT ln(3.1415926);

-- Returns 2.302585092994046
SELECT ln(10);

-- Returns 4.605170185988091
SELECT ln(100);

-- Returns NULL (negative input)
SELECT ln(-1);

-- Returns NULL
SELECT ln(null);

Table data

The following examples use the mf_math_fun_t sample table. To create and populate the table, run:

CREATE TABLE IF NOT EXISTS mf_math_fun_t (
    int_data     INT,
    bigint_data  BIGINT,
    double_data  DOUBLE,
    decimal_data DECIMAL,
    float_data   FLOAT,
    string_data  STRING
);

INSERT INTO mf_math_fun_t VALUES
(null, -10, 0.525, 0.525BD, CAST(0.525 AS FLOAT), '10'),
(-20, null, -0.1, -0.1BD, CAST(-0.1 AS FLOAT), '-10'),
(0, -1, null, 20.45BD, CAST(-1 AS FLOAT), '30'),
(-40, 4, 0.89, null, CAST(0.89 AS FLOAT), '-30'),
(5, -50, -1, -1BD, null, '50'),
(-60, 6, 1.5, 1.5BD, CAST(1.5 AS FLOAT), '-50'),
(-1, -70, -7.5, -7.5BD, CAST(-7.5 AS FLOAT), null),
(-80, 1, -10.2, -10.2BD, CAST(-10.2 AS FLOAT), '-1'),
(9, -90, 2.58, 2.58BD, CAST(2.58 AS FLOAT), '0'),
(-100, 10, -5.8, -5.8BD, CAST(-5.8 AS FLOAT), '-90');

Calculate the natural logarithm across all numeric columns:

SELECT
    ln(bigint_data)  AS bigint_new,
    ln(double_data)  AS double_new,
    ln(decimal_data) AS decimal_new,
    ln(string_data)  AS string_new
FROM mf_math_fun_t;

The following result is returned:

+--------------------+----------------------+---------------------+---------------------+
| bigint_new         | double_new           | decimal_new         | string_new          |
+--------------------+----------------------+---------------------+---------------------+
| NULL               | -0.6443570163905132  | -0.6443570163905132 | 2.302585092994046   |
| NULL               | NULL                 | NULL                | NULL                |
| NULL               | NULL                 | 3.017982882488811   | 3.4011973816621555  |
| 1.3862943611198906 | -0.11653381625595151 | NULL                | NULL                |
| NULL               | NULL                 | NULL                | 3.912023005428146   |
| 1.791759469228055  | 0.4054651081081644   | 0.4054651081081644  | NULL                |
| NULL               | NULL                 | NULL                | NULL                |
| 0.0                | NULL                 | NULL                | NULL                |
| NULL               | 0.9477893989335261   | 0.9477893989335261  | NULL                |
| 2.302585092994046  | NULL                 | NULL                | NULL                |
+--------------------+----------------------+---------------------+---------------------+

Related functions

LN is a mathematical function. For related functions, see Mathematical functions.

Related logarithmic and exponential functions:

  • LOG — logarithm with a custom base

  • LOG2 — logarithm base 2

  • LOG10 — logarithm base 10

  • EXP — inverse of LN; returns e raised to the power of the argument