std::exp, std::expf, std::expl_C++中文网

定义于头文件 <cmath>

(1)

float       exp ( float arg );

float       expf( float arg );

(C++11 起)

double      exp ( double arg );

(2)
(3)

long double exp ( long double arg );

long double expl( long double arg );

(C++11 起)

double      exp ( IntegralType arg );

(4) (C++11 起)

计算 e (欧拉数, 2.7182818 )的 arg 次幂。

4) 接受任何整数类型参数的重载集或函数模板。等价于 2) (将参数转型为 double )。

参数

返回值

若不出现错误,则返回 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 则保证下溢。

示例

可能的输出:

exp(1) = 2.71828
FV of $100, continuously compounded at 3% for 1 year = 103.045
exp(-0) = 1
exp(-Inf) = 0
exp(710) = inf
    errno == ERANGE: Numerical result out of range
    FE_OVERFLOW raised

参阅