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

log2f函数


概要:
#include <math.h>
float log2f(float x);

描述:

该函数是以2为底数的对数函数,计算log2x的值。

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

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


参数:
float x

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


返回值:

函数返回log2x


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

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

int main(void)
{
    float x = 8.0f;
    float y;

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

    return 0;
}

输出:

The base-2 logarithm of 8.000000 is 3.000000.


相关内容:
log2 double类型的以2为底数的对数函数。
log2l long double类型的以2为底数的对数函数。