名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | 數值‎ | 特殊函式
 
 
 
 
定義於標頭檔案 <cmath>
(1)
float       expint ( float num );

double      expint ( double num );

long double expint ( long double num );
(C++17 起)
(直至 C++23)
/* 浮點型別 */ expint( /* 浮點型別 */ num );
(C++23 起)
float       expintf( float num );
(2) (C++17 起)
long double expintl( long double num );
(3) (C++17 起)
定義於標頭檔案 <cmath>
template< class Integer >
double      expint ( Integer num );
(A) (C++17 起)
1-3) 計算 num指數積分 庫為所有無 cv 限定的浮點型別(作為引數 num 的型別)提供了 std::expint 的過載。(C++23 起)
A) 為所有整數型別提供了額外的過載,它們被視為 double

目錄

[編輯] 引數

num - 浮點值或整數值

[編輯] 返回值

若無錯誤發生,返回 num 的指數積分值,即 -
-num
e-t
t
dt

[編輯] 錯誤處理

錯誤可能按 math_errhandling 中指定的方式報告。

  • 如果引數是 NaN,則返回 NaN 且不報告域錯誤。
  • 若引數為 ±0,則返回 -∞。

[編輯] 註釋

不支援 C++17 但支援 ISO 29124:2010 的實現,如果實現定義的 __STDCPP_MATH_SPEC_FUNCS__ 的值至少為 201003L 並且使用者在包含任何標準庫標頭檔案之前定義了 __STDCPP_WANT_MATH_SPEC_FUNCS__,則提供此函式。

不支援 ISO 29124:2010 但支援 TR 19768:2007 (TR1) 的實現,在標頭檔案 tr1/cmath 和名稱空間 std::tr1 中提供此函式。

此函式的實現也可在 boost.math 中找到

不要求完全按照 (A) 提供額外的過載。它們只需要足以確保對於整數型別的引數 numstd::expint(num) 具有與 std::expint(static_cast<double>(num)) 相同的效果。

[編輯] 示例

#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);
}

輸出

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

[編輯] 外部連結

Weisstein, Eric W. "指數積分。" 來自 MathWorld — Wolfram Web 資源。