std::exp2, std::exp2f, std::exp2l
提供: cppreference.com
ヘッダ <cmath> で定義 | ||
float exp2 (float n ); float exp2f(float n ); | (1) | (C++11以上) |
double exp2 (double n ); | (2) | (C++11以上) |
longdouble exp2 (longdouble n ); longdouble exp2l(longdouble n ); | (3) | (C++11以上) |
double exp2 ( 整数型 n ); | (4) | (C++11以上) |
1-3) 2 の
n
乗を計算します。目次 |
[編集]引数
n | - | 浮動小数点または整数型の値 |
[編集]戻り値
エラーが発生しなければ、 2 を底とする n
の指数 (2n
) が返されます。
オーバーフローによる値域エラーが発生した場合、 +HUGE_VAL
、 +HUGE_VALF
または +HUGE_VALL
が返されます。
アンダーフローによる値域エラーが発生した場合、 (丸めた後の) 正しい結果が返されます。
[編集]エラー処理
math_errhandling で規定されている通りにエラーが報告されます。
処理系が IEEE 浮動小数点算術 (IEC 60559) をサポートしている場合、
- 引数が ±0 であれば、 1 が返されます。
- 引数が -∞ であれば、 +0 が返されます。
- 引数が +∞ であれば、 +∞ が返されます。
- 引数が NaN であれば、 NaN が返されます。
[編集]例
Run this code
#include <iostream>#include <cmath>#include <cerrno>#include <cstring>#include <cfenv>#pragma STDC FENV_ACCESS ONint main(){std::cout<<"exp2(4) = "<< std::exp2(4)<<'\n'<<"exp2(0.5) = "<< std::exp2(0.5)<<'\n'<<"exp2(-4) = "<< std::exp2(-4)<<'\n';// 特殊な値std::cout<<"exp2(-0) = "<< std::exp2(-0.0)<<'\n'<<"exp2(-Inf) = "<< std::exp2(-INFINITY)<<'\n';// エラー処理errno=0;std::feclearexcept(FE_ALL_EXCEPT);std::cout<<"exp2(1024) = "<< std::exp2(1024)<<'\n';if(errno==ERANGE)std::cout<<" errno == ERANGE: "<<std::strerror(errno)<<'\n';if(std::fetestexcept(FE_OVERFLOW))std::cout<<" FE_OVERFLOW raised\n";}
出力例:
exp2(4) = 16 exp2(0.5) = 1.41421 exp2(-4) = 0.0625 exp2(-0) = 1 exp2(-Inf) = 0 exp2(1024) = inf errno == ERANGE: Numerical result out of range FE_OVERFLOW raised
[編集]関連項目
(C++11)(C++11) | e の x 乗 (ex) を計算します (関数) |
(C++11)(C++11)(C++11) | e の x 乗から1引いた値 (ex-1) を計算します (関数) |
(C++11)(C++11)(C++11) | 指定された値の2を底とする対数 (log2(x)) を計算します (関数) |
exp2 の C言語リファレンス |