Namespaces
Variants

std:: expint, std:: expintf, std:: expintl

From cppreference.net
Definiert im Header <cmath>
(1)
float expint ( float num ) ;

double expint ( double num ) ;

long double expint ( long double num ) ;
(seit C++17)
(bis C++23)
/* floating-point-type */ expint ( /* floating-point-type */ num ) ;
(seit C++23)
float expintf ( float num ) ;
(2) (seit C++17)
long double expintl ( long double num ) ;
(3) (seit C++17)
Definiert im Header <cmath>
template < class Integer >
double expint ( Integer num ) ;
(A) (seit C++17)
1-3) Berechnet das Exponentialintegral von num . Die Bibliothek bietet Überladungen von std::expint für alle cv-unqualifizierten Gleitkommatypen als Typ des Parameters num an. (seit C++23)
A) Zusätzliche Überladungen werden für alle Ganzzahltypen bereitgestellt, die als double behandelt werden.

Inhaltsverzeichnis

Parameter

num - Gleitkomma- oder Ganzzahlwert

Rückgabewert

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

Fehlerbehandlung

Fehler können gemäß den Angaben in math_errhandling gemeldet werden.

  • Wenn das Argument NaN ist, wird NaN zurückgegeben und kein Domänenfehler gemeldet.
  • Wenn das Argument ±0 ist, wird -∞ zurückgegeben.

Hinweise

Implementierungen, die C++17 nicht unterstützen, aber ISO 29124:2010 unterstützen, stellen diese Funktion bereit, wenn __STDCPP_MATH_SPEC_FUNCS__ von der Implementierung auf einen Wert von mindestens 201003L definiert wird und wenn der Benutzer __STDCPP_WANT_MATH_SPEC_FUNCS__ definiert, bevor er Standardbibliotheksheader einbindet.

Implementierungen, die ISO 29124:2010 nicht unterstützen, aber TR 19768:2007 (TR1) unterstützen, stellen diese Funktion im Header tr1/cmath und im Namespace std::tr1 bereit.

Eine Implementierung dieser Funktion ist ebenfalls in boost.math verfügbar .

Die zusätzlichen Überladungen müssen nicht exakt wie (A) bereitgestellt werden. Sie müssen lediglich sicherstellen, dass für ihr Argument num vom Ganzzahltyp std :: expint ( num ) die gleiche Wirkung hat wie std :: expint ( static_cast < double > ( num ) ) .

Beispiel

#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}; // Vollblock: '█'
            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-Konstante = " << -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);
}

Ausgabe:

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

Externe Links

Weisstein, Eric W. "Exponential Integral." Von MathWorld — Eine Wolfram Web Resource.