exp, expf, expl
来自 cppreference.cn
定义于头文件 <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
|