C++学习------cmath头文件的源码学习07

163 阅读1分钟

携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第29天,点击查看活动详情

续接上文:C++学习------cmath头文件的源码学习06

函数族定义---幂函数

pow---计算baseexponentbase^{exponent}

double pow (double base     , double exponent);

示例:

  printf ("7 ^ 3 = %f\n", pow (7.0, 3.0) );
  printf ("4.73 ^ 12 = %f\n", pow (4.73, 12.0) );
  printf ("32.01 ^ 1.54 = %f\n", pow (32.01, 1.54) );
  //计算结果
7 ^ 3 = 343.000000
4.73 ^ 12 = 125410439.217423
32.01 ^ 1.54 = 208.036691

如上,计算737^3为7 * 7 * 7为343,计算幂函数的值。

sqrt---计算x开平方

double sqrt (double x);

示例:

  param = 1024.0;
  result = sqrt (param);
  printf ("sqrt(%f) = %f\n", param, result );
  //计算结果
sqrt(1024.000000) = 32.000000

cbrt---计算x开立方

double cbrt (double x);

示例:

  param = 27.0;
  result = cbrt (param);
  printf ("cbrt (%f) = %f\n", param, result);
  //计算结果
cbrt (27.000000) = 3.000000

hypot---计算sqrt(x2+y2)sqrt(x^2+y^2)

double hypot (double x     , double y);

示例,也即是计算确定两条指教边之后的三角形的斜边长度:

  leg_x = 3;
  leg_y = 4;
  result = hypot (leg_x, leg_y);
  printf ("%f, %f and %f form a right-angled triangle.\n",leg_x,leg_y,result);
  //计算结果
3.000000, 4.000000 and 5.000000 form a right-angled triangle.

函数族定义---误差与伽马函数

erf---返回误差函数值erf(x)

double erf (double x);

误差函数图像如下,可以看到,误差函数过(0,0)点,当x->正无穷时,函数值趋向1,当x->负无穷时,函数值趋向-1:

image.png

erfc---返回1-erf(x)

double erfc (double x);

也叫做余差函数,是1-erf(x)的值,过点(0,1),当x->正无穷时,函数值趋向0,当x->负无穷时,函数值趋向2。

image.png

tgamma---返回tgamma(x)的值

double tgamma (     double x);

函数图像如下:

image.png

lgamma---返回lgmma(x)的值

double lgamma (double x)

函数图像如下,可以看到,是取logetgamma(x)log_e{|tgamma(x)|}

image.png

后续函数分析见后文