![]() |
deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
|
Namespaces | |
| namespace | internal |
Enumerations | |
| enum class | PolynomialEvalScheme : int { estrin , horner } |
Functions | |
| template<int degree, typename Number , bool ensure_correct_treatment_of_zero = true, bool ensure_correct_treatment_of_infinity = true, PolynomialEvalScheme polynomial_evaluation_scheme = PolynomialEvalScheme::horner> | |
| Number | exp (Number x) |
|
strong |
Enumeration of available polynomial evaluation schemes for the correction polynomial in fast_exp_approximation().
| Enumerator | |
|---|---|
| estrin | |
| horner | |
Definition at line 414 of file fast_transcendental.h.
|
inline |
This function provides a fully vectorizable algorithm for approximating the exponential function. In contrast to the standard std::exp() implementation, this algorithm is designed for SIMD execution and therefore offers significant performance advantages in vectorized computations while maintaining high accuracy. The main algorithm is briefly summarized here. For more details see [204].
The algorithm is based on the IEEE-754 floating-point representation
\[ (-1)^s 2^{p-b} (1+m), \]
where \(s\) is the sign bit, \(p\) is the exponent and \(m\) is the mantissa with \(0 \le m < 1\). \(b\) is the bias, a constant depending only on the specific type.
For the exponential function one can write
\[ \exp(x) = 2^{x \log_2(e)} = 2^y = 2^{y_i}2^{y_f}, \]
where \(y = x \log_2(e)\), \(y_i = \lfloor y \rfloor\) is the integer part, and \(y_f = y - y_i\) is the fractional part. From the IEEE-754 expression one can identify
\[ s = 0,\qquad 2^{y_i} = 2^{p-b},\qquad 2^{y_f} = 1 + m. \]
The integer exponent \(y_i\) can be computed directly. However, although \(y_f\) is known, reconstructing the mantissa \(m = 2^{y_f} - 1\) still requires evaluating \(2^{y_f}\), which is transcendental and therefore expensive.
To avoid transcendental operations, a correction function
\[ K(y_f) = 1 + y_f - 2^{y_f}, \]
which is approximated using a polynomial of configurable degree, is introduced. With this approximation, the mantissa can be written as
\[ m = y_f - K(y_f). \]
The accuracy of the exponential approximation depends primarily on the polynomial used for \(K(y_f)\). The degree of the polynomial can be chosen using the template parameter degree. Supported degrees are in the range [3, 11]. Higher degrees typically improve accuracy at the expense of additional compute cost. In many applications, a degree of 5 already yields an excellent balance between precision and performance, but users may tune it depending on their specific requirements.
Once the mantissa and exponent have been computed, the final floating-point value is assembled through internal bit manipulation that constructs the correct IEEE-754 representation. For further algorithmic details, see the referenced literature.
This function optionally performs lower- and upper-bound checks on the input values. If enabled:
0.+∞. These checks ensure numerical safety but incur additional runtime overhead. They may be disabled when the user can guarantee that inputs lie within the representable range.Two schemes are available for evaluating the correction polynomial: (Horner's method)[https://en.wikipedia.org/wiki/Horner%27s_method], which minimizes the operation count, and (Estrin's method)[https://en.wikipedia.org/wiki/Estrin%27s_scheme], which performs slightly more operations but makes better use of modern hardware parallelism. The preferable scheme can vary depending on the application and system architecture and should be assessed separately for each use case.
| degree | Degree of the polynomial used to approximate the correction function. |
| Number | The floating-point data type. Only double and float are supported. |
| width | The SIMD vector width. |
| ensure_correct_treatment_of_zero | Whether to perform an underflow check. |
| ensure_correct_treatment_of_infinity | Whether to perform an overflow check. |
| polynomial_evaluation_scheme | The polynomial evaluation scheme to be used for the evaluation of the correction function. |
| x | The vector of values at which the exponential function is approximated. |
Definition at line 514 of file fast_transcendental.h.