exp2, exp2f, exp2l
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <math.h> で定義
|
||
float exp2f( float n ); |
(1) | (C99以上) |
double exp2( double n ); |
(2) | (C99以上) |
long double exp2l( long double n ); |
(3) | (C99以上) |
| ヘッダ <tgmath.h> で定義
|
||
#define exp2( n ) |
(4) | (C99以上) |
1-3) 2 の
n 乗を計算します。4) 型総称マクロ。
n が long double 型の場合は exp2l が呼ばれます。 そうでなく、 n が整数型または double 型の場合は exp2 が呼ばれます。 そうでなければ exp2f が呼ばれます。引数
| n | - | 浮動小数点値 |
戻り値
エラーが発生しなければ、 2 を底とする n の指数 (2n
) が返されます。
オーバーフローによる値域エラーが発生した場合、 +HUGE_VAL、 +HUGE_VALF または +HUGE_VALL が返されます。
アンダーフローによる値域エラーが発生した場合、 (丸めた後の) 正しい結果が返されます。
エラー処理
math_errhandling で規定されている通りにエラーが報告されます。
処理系が IEEE 浮動小数点算術 (IEC 60559) をサポートしている場合、
- 引数が ±0 であれば、 1 が返されます。
- 引数が -∞ であれば、 +0 が返されます。
- 引数が +∞ であれば、 +∞ が返されます。
- 引数が NaN であれば、 NaN が返されます。
例
Run this code
#include <stdio.h>
#include <math.h>
#include <float.h>
#include <errno.h>
#include <fenv.h>
#pragma STDC FENV_ACCESS ON
int main(void)
{
printf("exp2(5) = %f\n", exp2(5));
printf("exp2(0.5) = %f\n", exp2(0.5));
printf("exp2(-4) = %f\n", exp2(-4));
// special values
printf("exp2(-0.9) = %f\n", exp2(-0.9));
printf("exp2(-Inf) = %f\n", exp2(-INFINITY));
//error handling
errno = 0; feclearexcept(FE_ALL_EXCEPT);
printf("exp2(1024) = %f\n", exp2(1024));
if(errno == ERANGE) perror(" errno == ERANGE");
if(fetestexcept(FE_OVERFLOW)) puts(" FE_OVERFLOW raised");
}
出力例:
exp2(5) = 32.000000
exp2(0.5) = 1.414214
exp2(-4) = 0.062500
exp2(-0.9) = 0.535887
exp2(-Inf) = 0.000000
exp2(1024) = Inf
errno == ERANGE: Result too large
FE_OVERFLOW raised
参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.12.6.2 The exp2 functions (p: 242-243)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- F.10.3.2 The exp2 functions (p: 521)
- C99 standard (ISO/IEC 9899:1999):
- 7.12.6.2 The exp2 functions (p: 223)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- F.9.3.2 The exp2 functions (p: 458)
関連項目
(C99)(C99) |
e の x 乗 (ex) を計算します (関数) |
(C99)(C99)(C99) |
e の x 乗から1を引いた値 (ex-1) を計算します (関数) |
(C99)(C99)(C99) |
2を底とする対数 (log2(x)) を計算します (関数) |
exp2 の C++リファレンス
| |