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 的以 e 为底的指数函数值 (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 The exp functions (p: TBD)
- 7.25 Type-generic math <tgmath.h> (p: TBD)
- F.10.3.1 The exp functions (p: TBD)
- C17 标准 (ISO/IEC 9899:2018)
- 7.12.6.1 The exp functions (p: 175)
- 7.25 Type-generic math <tgmath.h> (p: 272-273)
- F.10.3.1 The exp functions (p: 379)
- C11 标准 (ISO/IEC 9899:2011)
- 7.12.6.1 The exp functions (p: 242)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- F.10.3.1 The exp functions (p: 520)
- C99 标准 (ISO/IEC 9899:1999)
- 7.12.6.1 The exp functions (p: 223)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- F.9.3.1 The exp functions (p: 458)
- C89/C90 标准 (ISO/IEC 9899:1990)
- 4.5.4.1 The exp function
[编辑] 参见
(C99)(C99)(C99) |
计算给定幂的 2 次方 (2x) (函数) |
(C99)(C99)(C99) |
计算给定幂的 e 次方,减一 (ex-1) (函数) |
(C99)(C99) |
计算自然对数(以 e 为底) (ln(x)) (函数) |
(C99)(C99)(C99) |
计算复数以 e 为底的指数函数 (函数) |
C++ 文档 关于 exp
|