Calculates
ex -
1
. For values of x close to 0, the exact sum of
expm1(x) + 1
is much closer to
the true result of
ex
than exp(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:expm1("value")
and:
logscale Syntaxmath:expm1(field="value")
These examples show basic structure only.
math:expm1()
Examples
Click
next to an example below to get the full details.Calculate e
Raised to Power Minus One
Calculate e^x - 1
using the math:expm1()
or
math:expm1()
functions
Query
x := 0.00001
| math:expm1(x, as=precise_result)
| math:exp(x, as=standard_result)
Introduction
In this example, the math:expm1()
function and
math:exp()
function are used to calculate
e^x - 1
for a small value
of x
, demonstrating the superior precision of
math:expm1()
compared to using
math:exp()
and subtracting 1
.
Step-by-Step
Starting with the source repository events.
- logscale
x := 0.00001
Assigns a very small double-precision floating-point value
0.00001
to a field named x. This small value near zero demonstrates wheremath:expm1()
provides better numerical precision. - logscale
| math:expm1(x, as=precise_result)
Calculates
e^x - 1
for the value in field x and returns the result in a new field named precise_result. If theas
parameter is not specified, the result is returned in a field named _expm1 as default. - logscale
| math:exp(x, as=standard_result)
Calculates
e^x
for the value in field x and returns the result in a new field named standard_result. If theas
parameter is not specified, the result is returned in a field named _exp as default. Event Result set.
Summary and Results
The query is used to calculate exponential values minus one with high
precision, which is particularly important in scientific and financial
calculations involving very small values. The
math:exp(x)
function is also mentioned in this
query to show that it is less precise due to floating-point rounding
compared to the math:expm1()
function.
The precise_result field contains the more accurate
calculation using math:expm1()
, while
standard_result shows the result of using
math:exp()
and subtracting 1
.
This query is useful, for example, to calculate small percentage changes in financial applications, compute precise scientific measurements near baseline values and analyze small deviations in statistical data.
Sample output from the incoming example data:
precise_result | standard_result |
---|---|
0.0000100000050000017 | 0.0000100000050000166 |
The results show that math:expm1()
provides more
precise calculations for small values. For values close to zero, the
difference between the two methods becomes significant in applications
requiring high precision.
Note that while the difference between the two methods may appear small, it becomes crucial in applications requiring high precision, especially when dealing with very small values or when performing many successive calculations.
In short, best practise is to:
Use math:expm1(x)
instead of
when:
math:exp(x)
- 1
x is close to 0
Precision is important
Working with small values
Use math:exp(x)
- 1 when:
x is larger
Extreme precision is not required
Performance is more important than precision