std::expint, std::expintf, std::expintl
来自 cppreference.cn
定义于头文件 <cmath> |
||
(1) | ||
float expint ( float num ); double expint ( double num ); |
(C++17 起) (C++23 前) |
|
/* floating-point-type */ expint( /* floating-point-type */ 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 起) |
A) 为所有整数类型提供额外重载,它们被视为 double 类型。
目录 |
[编辑] 参数
num | - | 浮点或整数值 |
[编辑] 返回值
如果没有错误发生,则返回 num 的指数积分值,即 -∫∞-num
e-t |
t |
[编辑] 错误处理
错误可能按照 math_errhandling 中的规定报告。
- 如果参数是 NaN,则返回 NaN 且不报告域错误。
- 如果参数是 ±0,则返回 -∞。
[编辑] 注解
不支持 C++17 但支持 ISO 29124:2010 的实现,如果定义了 __STDCPP_MATH_SPEC_FUNCS__
并且用户在包含任何标准库头文件之前定义了 __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}; // 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 资源。 |