std:: expint, std:: expintf, std:: expintl
| 
           定义于头文件
            
            
             <cmath>
            
            | ||
| (1) | ||
| 
           
           
           
            
             float
            
            expint
            
             (
            
            
             float
            
            num
            
             )
            
            
             ;
            
             
             
              double
             
             expint
             
              (
             
             
              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 起) | 
| 目录 | 
参数
| num | - | 浮点数或整数值 | 
返回值
If no errors occur, value of the exponential integral of num , that is - ∫ ∞-num
| e -t | 
| t | 
错误处理
错误报告方式可按照 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) 的形式提供。只需确保对于整数类型的实参 num , std :: 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}; // 全角块: '█' 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
                                          █ │
                                        ▆ █ │
                                        █ █ │
                                      █ █ █ │
                                    ▆ █ █ █ │
                                ▁ ▆ █ █ █ █ │
                            ▂ ▅ █ █ █ █ █ █ │
▁ ▁ ▁ ▁ ▁ ▁ ▁ ▂ ▂ ▃ ▃ ▄ ▆ ▇ █ █ █ █ █ █ █ █
        外部链接
| 魏斯坦, 埃里克·W. "指数积分." 摘自 MathWorld —— 一个 Wolfram 网络资源。 |