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 的底 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 <stdio.h> #include <math.h> #include <float.h> #include <errno.h> #include <fenv.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)); // 特殊值 printf("exp(-0) = %f\n", exp(-0.0)); printf("exp(-Inf) = %f\n", exp(-INFINITY)); // 错误处理 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引用
- C11 standard (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 standard (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 standard (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底指数  (函数)  |