Namespaces
Variants

exp2, exp2f, exp2l

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
(C23)
exp2
(C99)
(C99)
(C23)
(C23)

Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
ヘッダーで定義 <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) 与えられたべき乗 n に対する2のべき乗を計算します。
4) 型総称マクロ: n の型が long double の場合、 exp2l が呼び出される。それ以外の場合、 n が整数型または double 型の場合、 exp2 が呼び出される。それ以外の場合、 exp2f が呼び出される。

目次

翻訳の説明: - 「Contents」を「目次」に翻訳しました - HTMLタグ、属性、
タグ内のテキストは翻訳していません
- C++固有の用語(Parameters、Return value、Error handling、Example、References、See also)は原文のまま保持しました
- 書式と構造は完全に維持されています

パラメータ

n - 浮動小数点値

戻り値

エラーが発生しない場合、基数 2 n 乗( 2 n
)が返されます。

オーバーフローによる範囲エラーが発生した場合、 +HUGE_VAL +HUGE_VALF または +HUGE_VALL が返されます。

アンダーフローによる範囲エラーが発生した場合、正しい結果(丸め後)が返されます。

エラーハンドリング

エラーは math_errhandling で指定された通りに報告されます。

IEEE浮動小数点演算(IEC 60559)を実装がサポートしている場合、

  • 引数が ±0 の場合、1 が返される
  • 引数が -∞ の場合、+0 が返される
  • 引数が +∞ の場合、+∞ が返される
  • 引数が NaN の場合、NaN が返される

#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <math.h>
#include <stdio.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));
    // 特殊値
    printf("exp2(-0.9) = %f\n", exp2(-0.9));
    printf("exp2(-Inf) = %f\n", exp2(-INFINITY));
    // エラー処理
    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

参考文献

  • C23規格 (ISO/IEC 9899:2024):
  • 7.12.6.2 exp2関数群 (p: TBD)
  • 7.25 総称数学 <tgmath.h> (p: TBD)
  • F.10.3.2 exp2関数群 (p: TBD)
  • C17規格 (ISO/IEC 9899:2018):
  • 7.12.6.2 exp2関数 (p: 177)
  • 7.25 総称数学 <tgmath.h> (p: 272-273)
  • F.10.3.2 exp2関数 (p: 379)
  • C11規格 (ISO/IEC 9899:2011):
  • 7.12.6.2 exp2関数 (p: 242-243)
  • 7.25 総称数学 <tgmath.h> (p: 373-375)
  • F.10.3.2 exp2関数 (p: 521)
  • C99規格 (ISO/IEC 9899:1999):
  • 7.12.6.2 exp2関数 (p: 223)
  • 7.22 総称数学 <tgmath.h> (p: 335-337)
  • F.9.3.2 exp2関数 (p: 458)

関連項目

(C99) (C99)
指定された累乗に e を累乗する ( e x )
(関数)
(C99) (C99) (C99)
指定された累乗に e を累乗し、1を引く ( e x -1 )
(関数)
(C99) (C99) (C99)
2を底とする対数を計算する ( log 2 (x) )
(関数)