非常教程

C参考手册

数值 | Numerics

exp

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

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
  • 如果参数是-∞,则返回+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));
    // 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):
    • 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函数

扩展内容

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 ++文档 |

C

C 语言是一门通用计算机编程语言,应用广泛。C 语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。