std::exp, std::expf, std::expl
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
| ヘッダ <cmath> で定義
|
||
| (1) | ||
float exp ( float arg ); |
||
float expf( float arg ); |
(C++11以上) | |
double exp ( double arg ); |
(2) | |
| (3) | ||
long double exp ( long double arg ); |
||
long double expl( long double arg ); |
(C++11以上) | |
double exp ( 整数型 arg ); |
(4) | (C++11以上) |
1-3) e (ネイピア数
2.7182818...) の arg 乗を計算します。引数
| arg | - | 浮動小数点または整数型の値 |
戻り値
エラーが発生しなければ、 e を底とする arg の指数 (earg
) が返されます。
オーバーフローによる値域エラーが発生した場合、 +HUGE_VAL、 +HUGE_VALF または +HUGE_VALL が返されます。
アンダーフローによる値域エラーが発生した場合、 (丸めの後の) 正しい結果が返されます。
エラー処理
math_errhandling で規定されている通りにエラーが報告されます。
処理系が IEEE 浮動小数点算術 (IEC 60559) をサポートしている場合、
- 引数が ±0 であれば、 1 が返されます。
- 引数が -∞ であれば、 +0 が返されます。
- 引数が +∞ であれば、 +∞ が返されます。
- 引数が NaN であれば、 NaN が返されます。
ノート
IEEE 互換の double 型に対して、 709.8 < arg であればオーバーフローが保証され、 arg < -708.4 であればアンダーフローが保証されます。
例
Run this code
#include <iostream>
#include <cmath>
#include <cerrno>
#include <cstring>
#include <cfenv>
#pragma STDC FENV_ACCESS ON
int main()
{
std::cout << "exp(1) = " << std::exp(1) << '\n'
<< "FV of $100, continuously compounded at 3% for 1 year = "
<< 100*std::exp(0.03) << '\n';
// 特殊な値
std::cout << "exp(-0) = " << std::exp(-0.0) << '\n'
<< "exp(-Inf) = " << std::exp(-INFINITY) << '\n';
// エラー処理
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) = 2.71828
FV of $100, continuously compounded at 3% for 1 year = 103.045
exp(-0) = 1
exp(-Inf) = 0
exp(710) = inf
errno == ERANGE: Numerical result out of range
FE_OVERFLOW raised
関連項目
(C++11)(C++11)(C++11) |
2 の x 乗 (2x) を計算します (関数) |
(C++11)(C++11)(C++11) |
e の x 乗から1引いた値 (ex-1) を計算します (関数) |
(C++11)(C++11) |
自然対数 (ln(x)) を計算します (関数) |
| e を底とする複素指数関数 (関数テンプレート) | |
| valarray の各要素に関数 std::exp を適用します (関数テンプレート) | |
exp の C言語リファレンス
| |