Calculates the natural logarithm of the sum of field value and
1. For small values of x
, the
result of log1p(x)
is much
closer to the true result of ln(1 +
x)
than the floating-point evaluation of
log(1.0+x)
.
Note
Math functions on ARM architecture may return different results in very high-precision calculationsc compared to Intel/AMD architectures.
Hide omitted argument names for this function
Omitted Argument NamesThe argument name for
field
can be omitted; the following forms of this function are equivalent:logscale Syntaxmath:log1p("value")
and:
logscale Syntaxmath:log1p(field="value")
These examples show basic structure only.
math:log1p()
Examples
Click
next to an example below to get the full details.Calculate Natural Logarithm of Value Plus One
Calculate the natural logarithm of (1 + x)
using the math:log1p()
function
Query
x := 0.0001
| math:log1p(x, as=log1p_result)
Introduction
In this example, the math:log1p()
function is used
to demonstrate accurate calculation of ln(1 + x)
,
particularly for small values where standard floating-point arithmetic
might lose precision.
Step-by-Step
Starting with the source repository events.
- logscale
x := 0.0001
Assigns a small value
0.0001
to a field named x. This demonstrates the function's precision advantage with small values. - logscale
| math:log1p(x, as=log1p_result)
Calculates
ln(1 + x)
for the value in field x and returns the result in a new field named log1p_result. If theas
parameter is not specified, the result is returned in a field named _log1p as default. Event Result set.
Summary and Results
The query is used to calculate ln(1 + x)
with high
precision, particularly beneficial for small values where standard
floating-point calculations might be inaccurate.
This query is useful, for example, when working with small incremental changes, calculating precise logarithmic values near 1, or in financial calculations involving rates close to zero.
Sample output from the incoming example data:
log1p_result |
---|
0.00009999999833333334 |
The result demonstrates the precise calculation of ln(1 +
0.0001)
. Note that for very small values, the result is close
to, but not exactly equal to, the input value. This is because
math:log1p()
provides better numerical accuracy
than calculating ln(1.0 + x)
directly, especially
important when working with small values where floating-point precision
matters.