std:: exp, std:: expf, std:: expl
|
ヘッダーで定義
<cmath>
|
||
| (1) | ||
|
float
exp
(
float
num
)
;
double
exp
(
double
num
)
;
|
(C++23まで) | |
|
/*floating-point-type*/
exp ( /*floating-point-type*/ num ) ; |
(C++23から)
(constexpr C++26から) |
|
|
float
expf
(
float
num
)
;
|
(2) |
(C++11から)
(constexpr C++26から) |
|
long
double
expl
(
long
double
num
)
;
|
(3) |
(C++11から)
(constexpr C++26から) |
|
SIMDオーバーロード
(C++26から)
|
||
|
ヘッダーで定義
<simd>
|
||
|
template
<
/*math-floating-point*/
V
>
constexpr
/*deduced-simd-t*/
<
V
>
|
(S) | (C++26から) |
|
追加のオーバーロード
(C++11から)
|
||
|
ヘッダーで定義
<cmath>
|
||
|
template
<
class
Integer
>
double exp ( Integer num ) ; |
(A) | (constexpr C++26から) |
std::exp
のオーバーロードを提供します。
(C++23以降)
|
S)
SIMDオーバーロードは
v_num
に対して要素ごとの
std::exp
を実行します。
|
(C++26以降) |
|
A)
すべての整数型に対して追加のオーバーロードが提供されており、これらは
double
として扱われます。
|
(C++11以降) |
目次 |
パラメータ
| num | - | 浮動小数点または整数値 |
戻り値
エラーが発生しない場合、
e
を底とする
num
の指数関数
e
num
が返されます。
オーバーフローによる範囲エラーが発生した場合、
+HUGE_VAL
、
+HUGE_VALF
または
+HUGE_VALL
が返されます。
アンダーフローによる範囲エラーが発生した場合、正しい結果(丸め後)が返されます。
エラーハンドリング
エラーは math_errhandling で指定された通りに報告されます。
IEEE浮動小数点演算(IEC 60559)を実装がサポートしている場合、
- 引数が±0の場合、1が返されます。
- 引数が-∞の場合、+0が返されます。
- 引数が+∞の場合、+∞が返されます。
- 引数がNaNの場合、NaNが返されます。
注記
IEEE互換の型 double の場合、 709.8 < num であればオーバーフローが保証され、 num < -708.4 であればアンダーフローが保証されます。
追加のオーバーロードは (A) と完全に同一である必要はありません。それらは、整数型の引数 num に対して、 std :: exp ( num ) が std :: exp ( static_cast < double > ( num ) ) と同じ効果を持つことを保証するのに十分であればよいのです。
例
#include <cerrno> #include <cfenv> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <numbers> // #pragma STDC FENV_ACCESS ON consteval double approx_e() { long double e{1.0}; for (auto fac{1ull}, n{1llu}; n != 18; ++n, fac *= n) e += 1.0 / fac; return e; } int main() { std::cout << std::setprecision(16) << "exp(1) = e¹ = " << std::exp(1) << '\n' << "numbers::e = " << std::numbers::e << '\n' << "approx_e = " << approx_e() << '\n' << "FV of $100, continuously compounded at 3% for 1 year = " << std::setprecision(6) << 100 * std::exp(0.03) << '\n'; // special values std::cout << "exp(-0) = " << std::exp(-0.0) << '\n' << "exp(-Inf) = " << std::exp(-INFINITY) << '\n'; // error handling errno = 0; std::feclearexcept(FE_ALL_EXCEPT); std::cout << "exp(710) = " << std::exp(710) << '\n'; if (errno == ERANGE) std::cout << " errno == ERANGE: " << std::strerror(errno) << '\n'; if (std::fetestexcept(FE_OVERFLOW)) std::cout << " FE_OVERFLOW raised\n"; }
出力例:
exp(1) = e¹ = 2.718281828459045
numbers::e = 2.718281828459045
approx_e = 2.718281828459045
FV of $100, continuously compounded at 3% for 1 year = 103.045
exp(-0) = 1
exp(-Inf) = 0
exp(710) = inf
errno == ERANGE: 数値結果が範囲外です
FE_OVERFLOW raised
関連項目
|
(C++11)
(C++11)
(C++11)
|
指定された累乗に
2
を累乗した値を返す (
2
x
)
(関数) |
|
(C++11)
(C++11)
(C++11)
|
指定された累乗に
e
を累乗した値から
1
を引いた値を返す (
e
x
-1
)
(関数) |
|
(C++11)
(C++11)
|
自然(底
e
)対数を計算する (
ln(x)
)
(関数) |
|
複素数における底
e
の指数関数
(関数テンプレート) |
|
|
関数
std::exp
をvalarrayの各要素に適用する
(関数テンプレート) |
|
|
Cドキュメント
for
exp
|
|