std::expint, std::expintf, std::expintl
From cppreference.com
< cpp | numeric | special functions
| ヘッダー <cmath> で定義 |
||
| (1) | ||
float expint ( float num ); double expint ( double num ); long double expint ( long 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以降) |
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) すべての整数型に対する追加のオーバーロードが提供されます。これらは double として扱われます。
目次 |
[edit] Parameters
| num | - | 浮動小数点数または整数値 |
[edit] Return value
If no errors occur, value of the exponential integral of num, that is -∫∞-num
| e-t |
| t |
[edit] Error handling
math_errhandling で指定されたとおりにエラーが報告される場合があります。
- 引数がNaNの場合、NaNが返され、ドメインエラーは報告されません。
- If the argument is ±0, -∞ is returned.
[edit] Notes
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名前空間でこの関数が提供されます。
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); }
出力
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. |