ln
Use the ln() function to calculate the natural logarithm (base e) of a numeric value.
Syntax
ln(<number>)Parameters
number
integer, float
Yes
The numeric value for which to calculate the natural logarithm. The value must be greater than 0.
Returns
Type: float
Description: The ln() function returns the natural logarithm (base e) of the input value. If the input is null, zero, or negative, the function returns null or NaN.
Usage notes
Input type: XQL doesn't support NaN or infinite values as input and these value types also can not be returned.
Valid Input Range: The input
numbermust be strictly greater than 0. The natural logarithm is undefined for zero and negative numbers.Zero Input:
ln(0)returns negative infinity ornull.Negative Input:
ln(x)forx < 0returnsNaNornull.Null Handling: If the input expression is
null, the function returnsnull.Identity Value:
ln(1)always returns0.0, andln(e)returns1.0.Inverse Relationship: The
ln()function is the inverse ofexp(). That is,ln(exp(x)) = xandexp(ln(x)) = xforx > 0.Common Use Cases: This function is typically used within the
alterstage for logarithmic scaling, entropy calculations, growth rate analysis, and data normalization.
Examples
Example 1: Calculate natural logarithm of literal values
Goal: Calculate the natural logarithm for specific numeric literals to verify known mathematical results.
XQL code:
Explanation: ln(1) returns 0.0 (since e^0 = 1), ln(e) returns 1.0 (computed via ln(exp(1))), and ln(10) returns approximately 2.30259.
Output:
0.0
1.0
2.30259
Example 2: Calculate natural logarithm from a field value
Goal: Calculate the natural logarithm of values stored in a dataset field, filtering out non-positive values.
XQL code:
Explanation: This query first filters the dataset to ensure numeric_value contains only positive values, then computes the natural logarithm for each value using ln() in the alter stage.
Output:
101
1.0
0.0
102
10.0
2.30259
103
100.0
4.60517
Example 3: Use natural logarithm for logarithmic scaling
Goal: Apply logarithmic scaling to large numeric values to compress the range for analysis.
XQL code:
Explanation: This query applies ln() to the event_id field to create a logarithmically scaled version. This is useful for visualizing or analyzing data with a wide range of values.
Output:
101
4.61512
102
4.62497
103
4.63473
Related articles
Datasets:
xdr_data
Last updated
Was this helpful?
