C++ Reference: Standard C++ Library reference: C Library: cmath: exp

发布于:2022-12-06 ⋅ 阅读:(328) ⋅ 点赞:(0)

C++官网参考链接:https://cplusplus.com/reference/cmath/exp/

函数 
<cmath> <ctgmath>
exp
C90
double exp (double x);
C99
double exp  (double x); 
float expf (float x); 
long double expl (long double x);
C++98
double exp (double x);      
float exp (float x);
long double exp (long double x);
C++11
double exp (double x);      
float exp (float x);
long double exp (long double x);     
double exp (T x);           // additional overloads for integral types

计算指数函数
返回以e为底数的x为指数的函数,它是e的x次幂:e^x。
C99
头文件<tgmath.h>提供了该函数的泛型类型的宏版本。
C++98
该函数在<complex><valarray>中被重载(参见complex expvalarray exp) 
C++11
在此头文件(<cmath>)中为整型(integral types)提供了额外的重载:这些重载在计算之前有效地将x转换为double类型。
此函数在<complex><valarray>中也被重载(参见complex expvalarray exp)。

形参
x
指数值。

返回值
以e为底数,x为指数的幂值。
如果结果的绝对大小太大,不能用返回类型的值表示,函数返回HUGE_VAL(或HUGE_VALFHUGE_VALL)和适当的符号,并发生上溢范围错误:
C90(C++98)
如果发生上溢范围错误,则将全局变量errno设置为ERANGE
C99(C++11)
如果发生上溢范围错误: 
math_errhandling具有MATH_ERRNO集合:全局变量errno设置为ERANGE
math_errhandling具有MATH_ERREXCEPT集合:引发FE_OVERFLOW。 

用例
/* exp example */
#include <stdio.h>      /* printf */
#include <math.h>       /* exp */

int main ()
{
  double param, result;
  param = 5.0;
  result = exp (param);
  printf ("The exponential value of %f is %f.\n", param, result );
  return 0;
}
输出:

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到