C
数值 | Numerics

expf

exp, expf, expl

在头文件中定义
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)。

4)类型 - 泛型宏:如果arg的类型为long double,则调用expl。 否则,如果arg具有整数类型或类型double,则调用exp。 否则,调用expf。 如果arg是复数或虚数,那么宏调用相应的复数函数(cexpf,cexp,cexpl)。

参数

arg-floating point value

返回值

如果没有错误发生,arg的基e指数(earg

)被返回。

如果发生由溢出引起的范围错误,则返回+ HUGE_VAL,+ HUGE_VALF或+ HUGE_VALL。

如果由于下溢而发生范围错误,则返回正确的结果(舍入后)。

错误处理

按照math_errhandling中的指定报告错误。

如果实现支持IEEE浮点运算(IEC 60559),

  • 如果参数是±0,则返回1

注意

对于兼容IEEE的类型,如果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) // 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

参考

  • C11标准(ISO / IEC 9899:2011):

扩展内容

exp2exp2fexp2l(C99)(C99)(C99)计算2提高到给定的倍率(2x)(功能)
expper1expm1fexpm1l(C99)(C99)(C99)计算e增加到给定的倍率,减去一(ex-1)(函数)
loglogflogl(C99)(C99)计算自然(base-e)对数(ln(x))(函数)
cexpcexpfcexpl(C99)(C99)(C99)计算复数基-e指数(函数)

| 用于exp的C ++文档 |