ChengR

c标准头文件math.h中有两个与log有关的函数。

   

double __cdecl log(double _X);

double __cdecl log10(double _X);

   

其中log相当于数学中的ln(loge)

log10相当于数学中的lg

logelog10可以直接表示了。

 

   

#include <math.h>

#include <stdio.h>

const double e = exp(1.0);;//可以用这个方法获得比较精确的e值。

//exp()也是math.h中的函数,其功能是求e的幂

int main()

{

printf("%.6lf\n", log10(10.0));

printf("%.6lf\n", log(e));

return 0;

}

   

输出:

   

1.000000

1.000000

如果想表示logab的对数,可以用换底公式。

   

logab换成以10e为底的对数就好了。

例如:表示log28如下:

log28=lg8/lg2

   

#include <stdio.h>

#include <math.h>

int main()

{

printf("%.6lf\n", log10(8.0)/log10(2.0));

return 0;

}

输出:

   

3.000000

分类:

技术点:

相关文章:

  • 2021-11-30
  • 2021-11-30
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-07-08
猜你喜欢
  • 2021-12-18
  • 2021-12-18
  • 2021-12-10
  • 2021-11-30
  • 2022-12-23
  • 2021-12-06
相关资源
相似解决方案