Difference between revisions of "cpp/numeric/special functions/expint"
m (Typo Gompetz -> Gompertz) |
m (→Example: +`expint` outline.) |
||
Line 39: | Line 39: | ||
===Example=== | ===Example=== | ||
{{example|code= | {{example|code= | ||
− | + | {{cpp/numeric/draw_vbars}} | |
− | + | ||
int main() | int main() | ||
{ | { | ||
Line 46: | Line 46: | ||
<< "Ei(1) = " << std::expint(1) << '\n' | << "Ei(1) = " << std::expint(1) << '\n' | ||
<< "Gompertz constant = " << -std::exp(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); | ||
} | } | ||
− | |output= | + | |output=<nowiki/> |
Ei(0) = -inf | Ei(0) = -inf | ||
Ei(1) = 1.89512 | Ei(1) = 1.89512 | ||
Gompertz constant = 0.596347 | Gompertz constant = 0.596347 | ||
+ | █ ┬ 666.505 | ||
+ | █ │ | ||
+ | ▆ █ │ | ||
+ | █ █ │ | ||
+ | █ █ █ │ | ||
+ | ▆ █ █ █ │ | ||
+ | ▁ ▆ █ █ █ █ │ | ||
+ | ▂ ▅ █ █ █ █ █ █ │ | ||
+ | ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▂ ▂ ▃ ▃ ▄ ▆ ▇ █ █ █ █ █ █ █ █ ┴ 1.89512 | ||
}} | }} | ||
Revision as of 05:45, 24 June 2022
Defined in header <cmath>
|
||
double expint( double arg ); float expint( float arg ); |
(1) | (since C++17) |
double expint( IntegralType arg ); |
(2) | (since C++17) |
Contents |
Parameters
arg | - | value of a floating-point or Integral type |
Return value
If no errors occur, value of the exponential integral ofarg
, that is -∫∞-arge-t |
t |
Error handling
Errors may be reported as specified in math_errhandling
- If the argument is NaN, NaN is returned and domain error is not reported
- If the argument is ±0, -∞ is returned
Notes
Implementations that do not support C++17, but support ISO 29124:2010, provide this function if __STDCPP_MATH_SPEC_FUNCS__
is defined by the implementation to a value at least 201003L and if the user defines __STDCPP_WANT_MATH_SPEC_FUNCS__
before including any standard library headers.
Implementations that do not support ISO 29124:2010 but support TR 19768:2007 (TR1), provide this function in the header tr1/cmath
and namespace std::tr1
.
An implementation of this function is also available in boost.math
Example
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); }
Output:
Ei(0) = -inf Ei(1) = 1.89512 Gompertz constant = 0.596347 █ ┬ 666.505 █ │ ▆ █ │ █ █ │ █ █ █ │ ▆ █ █ █ │ ▁ ▆ █ █ █ █ │ ▂ ▅ █ █ █ █ █ █ │ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▂ ▂ ▃ ▃ ▄ ▆ ▇ █ █ █ █ █ █ █ █ ┴ 1.89512
External links
Weisstein, Eric W. "Exponential Integral." From MathWorld--A Wolfram Web Resource.