当前位置: C语言 -- 标准库 -- <math.h> -- log

log函数


概要:
#include <math.h>
double log(double x);

描述:

该函数是以e为底数的对数函数,即自然对数函数,计算logex的值。

如果参数x为负值,将发生域错误。

如果参数x等于0,将可能发生极点错误。


参数:
double x

参数为一个double类型的浮点数。


返回值:

函数返回logex


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
/*函数log范例*/

#include <math.h>
#include <stdio.h>

int main(void)
{
    double x = 8.0;
    double y;

    y = log(x);
    printf("The base-e logarithm of %.6f is %.6f.\n", x, y);

    return 0;
}

输出:

The base-e logarithm of 8.000000 is 2.079442.


相关内容:
logf float类型的自然对数函数。
logl long double类型的自然对数函数。