exp, expf, expl
來自 cppreference.com
定義於標頭檔案 <math.h> |
||
float expf( float arg ); |
(1) | (C99 起) |
double exp( double arg ); |
(2) | |
long double expl( long double arg ); |
(3) | (C99 起) |
定義於標頭檔案 <tgmath.h> |
||
#define exp( arg ) |
(4) | (C99 起) |
1-3) 計算 e(尤拉數,2.7182818...)的給定冪次 `arg`。
4) 型別泛型宏:如果 `arg` 的型別為 `long double`,則呼叫 `expl`。否則,如果 `arg` 具有整數型別或 `double` 型別,則呼叫 `exp`。否則,呼叫 `expf`。如果 `arg` 是複數或虛數,則該宏呼叫相應的複數函式(cexpf,cexp,cexpl)。
目錄 |
[編輯] 引數
arg | - | 浮點值 |
[編輯] 返回值
如果沒有錯誤發生,則返回 `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`,則保證下溢。
[編輯] 示例
執行此程式碼
#include <errno.h> #include <fenv.h> #include <float.h> #include <math.h> #include <stdio.h> // #pragma STDC FENV_ACCESS ON int main(void) { printf("exp(1) = %f\n", exp(1)); printf("FV of $100, continuously compounded at 3%% for 1 year = %f\n", 100*exp(0.03)); // special values printf("exp(-0) = %f\n", exp(-0.0)); printf("exp(-Inf) = %f\n", exp(-INFINITY)); //error handling errno = 0; feclearexcept(FE_ALL_EXCEPT); printf("exp(710) = %f\n", exp(710)); if (errno == ERANGE) perror(" errno == ERANGE"); if (fetestexcept(FE_OVERFLOW)) puts(" FE_OVERFLOW raised"); }
可能的輸出
exp(1) = 2.718282 FV of $100, continuously compounded at 3% for 1 year = 103.045453 exp(-0) = 1.000000 exp(-Inf) = 0.000000 exp(710) = inf errno == ERANGE: Numerical result out of range FE_OVERFLOW raised
[編輯] 參考
- C23 標準 (ISO/IEC 9899:2024)
- 7.12.6.1 exp 函式 (p: TBD)
- 7.25 型別通用數學 <tgmath.h> (p: TBD)
- F.10.3.1 exp 函式 (p: TBD)
- C17 標準 (ISO/IEC 9899:2018)
- 7.12.6.1 exp 函式 (p: 175)
- 7.25 型別通用數學 <tgmath.h> (p: 272-273)
- F.10.3.1 exp 函式 (p: 379)
- C11 標準 (ISO/IEC 9899:2011)
- 7.12.6.1 exp 函式 (p: 242)
- 7.25 型別通用數學 <tgmath.h> (p: 373-375)
- F.10.3.1 exp 函式 (p: 520)
- C99 標準 (ISO/IEC 9899:1999)
- 7.12.6.1 exp 函式 (p: 223)
- 7.22 型別通用數學 <tgmath.h> (p: 335-337)
- F.9.3.1 exp 函式 (p: 458)
- C89/C90 標準 (ISO/IEC 9899:1990)
- 4.5.4.1 exp 函式
[編輯] 另請參閱
(C99)(C99)(C99) |
計算 2 的給定冪 (2x) (函式) |
(C99)(C99)(C99) |
計算 e 的給定冪,減一 (ex-1) (函式) |
(C99)(C99) |
計算自然(底數e)對數 (ln(x)) (函式) |
(C99)(C99)(C99) |
計算複數以 e 為底的指數 (函式) |
C++ 文件 for exp
|