Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/numeric/special functions/expint"

From cppreference.com
m (Cubbi moved page cpp/numeric/special math/expint to cpp/numeric/special functions/expint: to special_functions)
m (.)
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{cpp/title|expint|expintf|expintl}}
 
{{cpp/title|expint|expintf|expintl}}
{{cpp/numeric/special_math/navbar}}
+
{{cpp/numeric/special_functions/navbar}}
 
{{dcl begin}}
 
{{dcl begin}}
{{dcl |num=1|since=c++17|
+
{{dcl header|cmath}}
double      expint( double arg );
+
{{dcl rev multi|num=1|since1=c++17|dcl1=
float      expint( float arg );
+
float      expint ( float num );
long double expint( long double arg );
+
double      expint ( double num );
float      expintf( float arg );
+
long double expint ( long double num );
long double expintl( long double arg );
+
|since2=c++23|dcl2=
 +
/* floating-point-type */ expint( /* floating-point-type */ num );
 
}}
 
}}
{{dcl |num=2|since=c++17|
+
{{dcl|num=2|since=c++17|
double      expint( IntegralType arg );
+
float      expintf( float num );
 +
}}
 +
{{dcl|num=3|since=c++17|
 +
long double expintl( long double num );
 +
}}
 +
{{dcl h|[[#Notes|Additional overloads]]}}
 +
{{dcl header|cmath}}
 +
{{dcl|num=A|since=c++17|
 +
template< class Integer >
 +
double      expint ( Integer num );
 
}}
 
}}
 
{{dcl end}}
 
{{dcl end}}
  
@1@ Computes the [[enwiki:Exponential integral|exponential integral]] of {{tt|arg}}.
+
@1-3@ Computes the {{enwiki|Exponential integral}} of {{c|num}}.{{rev inl|since=c++23| The library provides overloads of {{tt|std::expint}} for all cv-unqualified floating-point types as the type of the parameter {{c|num}}.}}
@2@ A set of overloads or a function template accepting an argument of any [[cpp/types/is_integral|integral type]]. Equivalent to {{v|1}} after casting the argument to {{c|double}}.
+
@A@ Additional overloads are provided for all integer types, which are treated as {{c/core|double}}.
  
 
===Parameters===
 
===Parameters===
 
{{par begin}}
 
{{par begin}}
{{par | arg | value of a floating-point or [[cpp/types/is_integral|Integral type]]}}
+
{{par|num|floating-point or integer value}}
 
{{par end}}
 
{{par end}}
  
 
===Return value===
 
===Return value===
If no errors occur, value of the exponential integral of {{tt|arg}}, that is {{math|-{{minteg|-arg|∞|{{mfrac|{{mexp|-t}}|t}}d''t''}}}}, is returned.
+
If no errors occur, value of the exponential integral of {{c|num}}, that is {{math|-{{minteg|-num|∞|{{mfrac|{{mexp|-t}}|t}}d''t''}}}}, is returned.
  
 
===Error handling===
 
===Error handling===
Errors may be reported as specified in [[cpp/numeric/math/math_errhandling|math_errhandling]]
+
Errors may be reported as specified in {{lc|math_errhandling}}.
 
+
* If the argument is NaN, NaN is returned and domain error is not reported.
* If the argument is NaN, NaN is returned and domain error is not reported
+
* If the argument is ±0, -∞ is returned.
* If the argument is ±0, -∞ is returned
+
  
 
===Notes===
 
===Notes===
{{cpp/numeric/special_math/older_impl_note}}
+
{{cpp/numeric/special functions/older impl note}}
  
An implementation of this function is also [http://www.boost.org/doc/libs/release/libs/math/doc/html/math_toolkit/expint/expint_i.html available in boost.math]
+
An implementation of this function is also [https://www.boost.org/doc/libs/release/libs/math/doc/html/math_toolkit/expint/expint_i.html available in boost.math].
 +
 
 +
{{cpp/numeric/special functions/additional integer overload note|expint}}
  
 
===Example===
 
===Example===
{{example|code=
+
{{example
 +
|code=
 +
#include <algorithm>
 
#include <cmath>
 
#include <cmath>
 
#include <iostream>
 
#include <iostream>
 +
#include <vector>
 +
 +
{{cpp/numeric/draw_vbars}}
 +
 
int main()
 
int main()
 
{
 
{
 
     std::cout << "Ei(0) = " << std::expint(0) << '\n'
 
     std::cout << "Ei(0) = " << std::expint(0) << '\n'
 
               << "Ei(1) = " << std::expint(1) << '\n'
 
               << "Ei(1) = " << std::expint(1) << '\n'
               << "Gompetz constant = " << -std::exp(1)*std::expint(-1) << '\n';
+
               << "Gompertz constant = " << -std::exp(1) * std::expint(-1) << '\n';
 +
   
 +
    std::vector<float> v;
 +
    for (float x{1.f}; x < 8.8f; x += 0.3565f)
 +
        v.push_back(std::expint(x));
 +
    draw_vbars<9, 1, 1>(v);
 
}
 
}
 
|output=
 
|output=
 
Ei(0) = -inf
 
Ei(0) = -inf
 
Ei(1) = 1.89512
 
Ei(1) = 1.89512
Gompetz constant = 0.596347
+
Gompertz constant = 0.596347
 +
                                          █ ┬ 666.505
 +
                                          █ │
 +
                                        ▆ █ │
 +
                                        █ █ │
 +
                                      █ █ █ │
 +
                                    ▆ █ █ █ │
 +
                                ▁ ▆ █ █ █ █ │
 +
                            ▂ ▅ █ █ █ █ █ █ │
 +
▁ ▁ ▁ ▁ ▁ ▁ ▁ ▂ ▂ ▃ ▃ ▄ ▆ ▇ █ █ █ █ █ █ █ █ ┴ 1.89512
 
}}
 
}}
  
 
===External links===
 
===External links===
[http://mathworld.wolfram.com/ExponentialIntegral.html Weisstein, Eric W. "Exponential Integral."] From MathWorld--A Wolfram Web Resource.
+
{{eli|[https://mathworld.wolfram.com/ExponentialIntegral.html Weisstein, Eric W. "Exponential Integral."] From MathWorld A Wolfram Web Resource.}}
  
[[de:cpp/numeric/special_math/expint]]
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
[[es:cpp/numeric/special_math/expint]]
+
[[fr:cpp/numeric/special_math/expint]]
+
[[it:cpp/numeric/special_math/expint]]
+
[[ja:cpp/numeric/special_math/expint]]
+
[[pt:cpp/numeric/special_math/expint]]
+
[[ru:cpp/numeric/special_math/expint]]
+
[[zh:cpp/numeric/special_math/expint]]
+

Latest revision as of 23:38, 16 October 2023

 
 
 
 
Defined in header <cmath>
(1)
float       expint ( float num );

double      expint ( double num );

long double expint ( long double num );
(since C++17)
(until C++23)
/* floating-point-type */ expint( /* floating-point-type */ num );
(since C++23)
float       expintf( float num );
(2) (since C++17)
long double expintl( long double num );
(3) (since C++17)
Defined in header <cmath>
template< class Integer >
double      expint ( Integer num );
(A) (since C++17)
1-3) Computes the Exponential integral of num. The library provides overloads of std::expint for all cv-unqualified floating-point types as the type of the parameter num.(since C++23)
A) Additional overloads are provided for all integer types, which are treated as double.

Contents

[edit] Parameters

num - floating-point or integer value

[edit] Return value

If no errors occur, value of the exponential integral of num, that is -∞-num
e-t
t
dt
, is returned.

[edit] Error handling

Errors may be reported as specified in math_errhandling.

  • If the argument is NaN, NaN is returned and domain error is not reported.
  • If the argument is ±0, -∞ is returned.

[edit] Notes

Implementations that do not support C++17, but support ISO 29124:2010, provide this function if __STDCPP_MATH_SPEC_FUNCS__ is defined by the implementation to a value at least 201003L and if the user defines __STDCPP_WANT_MATH_SPEC_FUNCS__ before including any standard library headers.

Implementations that do not support ISO 29124:2010 but support TR 19768:2007 (TR1), provide this function in the header tr1/cmath and namespace std::tr1.

An implementation of this function is also available in boost.math.

The additional overloads are not required to be provided exactly as (A). They only need to be sufficient to ensure that for their argument num of integer type, std::expint(num) has the same effect as std::expint(static_cast<double>(num)).

[edit] Example

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
 
template<int Height = 5, int BarWidth = 1, int Padding = 1, int Offset = 0, class Seq>
void draw_vbars(Seq&& s, const bool DrawMinMax = true)
{
    static_assert(0 < Height and 0 < BarWidth and 0 <= Padding and 0 <= Offset);
 
    auto cout_n = [](auto&& v, int n = 1)
    {
        while (n-- > 0)
            std::cout << v;
    };
 
    const auto [min, max] = std::minmax_element(std::cbegin(s), std::cend(s));
 
    std::vector<std::div_t> qr;
    for (typedef decltype(*std::cbegin(s)) V; V e : s)
        qr.push_back(std::div(std::lerp(V(0), 8 * Height,
                                        (e - *min) / (*max - *min)), 8));
 
    for (auto h{Height}; h-- > 0; cout_n('\n'))
    {
        cout_n(' ', Offset);
 
        for (auto dv : qr)
        {
            const auto q{dv.quot}, r{dv.rem};
            unsigned char d[]{0xe2, 0x96, 0x88, 0}; // Full Block: '█'
            q < h ? d[0] = ' ', d[1] = 0 : q == h ? d[2] -= (7 - r) : 0;
            cout_n(d, BarWidth), cout_n(' ', Padding);
        }
 
        if (DrawMinMax && Height > 1)
            Height - 1 == h ? std::cout << "┬ " << *max:
                          h ? std::cout << "│ "
                            : std::cout << "┴ " << *min;
    }
}
 
int main()
{
    std::cout << "Ei(0) = " << std::expint(0) << '\n'
              << "Ei(1) = " << std::expint(1) << '\n'
              << "Gompertz constant = " << -std::exp(1) * std::expint(-1) << '\n';
 
    std::vector<float> v;
    for (float x{1.f}; x < 8.8f; x += 0.3565f)
        v.push_back(std::expint(x));
    draw_vbars<9, 1, 1>(v);
}

Output:

Ei(0) = -inf
Ei(1) = 1.89512
Gompertz constant = 0.596347
                                          █ ┬ 666.505
                                          █ │
                                        ▆ █ │
                                        █ █ │
                                      █ █ █ │
                                    ▆ █ █ █ │
                                ▁ ▆ █ █ █ █ │
                            ▂ ▅ █ █ █ █ █ █ │
▁ ▁ ▁ ▁ ▁ ▁ ▁ ▂ ▂ ▃ ▃ ▄ ▆ ▇ █ █ █ █ █ █ █ █ ┴ 1.89512

[edit] External links

Weisstein, Eric W. "Exponential Integral." From MathWorld — A Wolfram Web Resource.