...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
#include <boost/math/special_functions/expint.hpp>
namespace boost{ namespace math{ template <class T> calculatedresulttype expint(unsigned n, T z); template <class T, class Policy> calculatedresulttype expint(unsigned n, T z, const Policy&); }} // namespaces
The return type of these functions is computed using the result
type calculation rules: the return type is double
if T is an integer type, and T otherwise.
The final Policy argument is optional and can be used to control the behaviour of the function: how it handles errors, what level of precision to use etc. Refer to the policy documentation for more details.
template <class T> calculatedresulttype expint(unsigned n, T z); template <class T, class Policy> calculatedresulttype expint(unsigned n, T z, const Policy&);
Returns the exponential integral En of z:
The following table shows the peak errors (in units of epsilon) found on various platforms with various floating point types, along with comparisons to other libraries. Unless otherwise specified any floating point type that is narrower than the one shown will have effectively zero error.
Table 7.77. Error rates for expint (En)
GNU C++ version 7.1.0 
GNU C++ version 7.1.0 
Sun compiler version 0x5150 
Microsoft Visual C++ version 14.1 


Exponential Integral En 
Max = 0.589ε (Mean = 0.0331ε) 
Max = 9.97ε (Mean = 2.13ε) 
Max = 9.97ε (Mean = 2.13ε) 
Max = 7.16ε (Mean = 1.85ε) 
Exponential Integral En: small z values 
Max = 0ε (Mean = 0ε) 
Max = 1.99ε (Mean = 0.559ε) 
Max = 1.99ε (Mean = 0.559ε) 
Max = 2.62ε (Mean = 0.531ε) 
Exponential Integral E1 
Max = 0.556ε (Mean = 0.0625ε) 
Max = 0.965ε (Mean = 0.414ε) 
Max = 0.965ε (Mean = 0.408ε) 
Max = 0.988ε (Mean = 0.486ε) 
The tests for these functions come in two parts: basic sanity checks use spot values calculated using Mathworld's online evaluator, while accuracy checks use highprecision test values calculated at 1000bit precision with NTL::RR and this implementation. Note that the generic and typespecific versions of these functions use differing implementations internally, so this gives us reasonably independent test data. Using our test data to test other "known good" implementations also provides an additional sanity check.
The generic version of this function uses the continued fraction:
for large x and the infinite series:
for small x.
Where the precision of x is known at compile time and
is 113 bits or fewer in precision, then rational approximations devised
by JM are used for the n
== 1
case.
For x <
1
the approximating form is a minimax
approximation:
and for x >
1
a Chebyshev interpolated approximation
of the form:
is used.