log2
计算以2为底的对数值。
接口定义
C interface:
float log2f(float x);
double log2(double x);
long double log2l(long double x);
Fortran interface:
RES = LOG2F(X);
RES = LOG2(X);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
x |
|
表示输入数据的浮点值。 |
输入 |
返回值
- 返回以2为底x的对数函数值y,y ∈ (-INF, +INF)。
- 输入x为±0,返回-∞。
- 输入x为1,返回0。
- 输入x为负数,返回nan。
- 输入x为-∞,返回nan。
- 输入x为+∞,返回+∞。
- 输入x为nan,返回nan。
依赖
C: "km.h"
示例
C interface:
// typical usage double x1 = 2.0, x2 = 0.5, x3 = 125, x4 = 5; // special handing double a = 0.0, b = INFINITY, c = -INFINITY, d = NAN, e = 1.0; // print result printf("base-5 logarithm of 125 = %.15f\n", log2(x3)/log2(x4)); printf("log2(1.0) = %.15f\n", log2(e)); printf("log2(2.0) = %.15f\n", log2(x1)); printf("log2(0.5) = %.15f\n", log2(x2)); printf("log2(0.0) = %.15f\n", log2(a)); printf("log2(INFINITY) = %.15f\n", log2(b)); printf("log2(-INFINITY) = %.15f\n", log2(c)); printf("log2(NAN) = %.15f\n", log2(d)); /* * base-5 logarithm of 125 = 3.000000000000000 * log2(1.0) = 0.000000000000000 * log2(2.0) = 1.000000000000000 * log2(0.5) = -1.000000000000000 * log2(0.0) = -inf * log2(INFINITY) = inf * log2(-INFINITY) = nan * log2(NAN) = nan * * */
Fortran interface:
REAL(8) :: X = 0.5 PRINT*, LOG2(X) ! ! OUTPUT ! -1.000000000000000 !
父主题: 指数和对数函数