R中的log2:如何计算指数和尾数
log2 in R: How to calculate the exponent and mantissa
有谁知道如何在 R 中执行相同的 MATLAB 函数 [F,E] = log2(X)
?
[F,E] = log2(X) returns arrays F and E such that X=F*2^E. The values
in F are typically in the range 0.5 <= abs(F) < 1.
见https://www.mathworks.com/help/matlab/ref/log2.html
For example in MATLAB,
[F,E] = log2(15)
F =
0.9375
E =
4
因此,
F*2^E = 15
我不完全确定你在问什么,但 log2
为你提供了 R 中以 2 为底的对数。例如
log2(2);
#[1] 1
log2(2^10)
#[1] 10
2^(log2(10))
#[1] 10
详情见?log
。
您需要手动计算它们。我不认为有一个内置的来提取它们。试试这个:
x<-15
E <- ifelse(x == 0, 0, floor(log2(abs(x)))+1 )
F<-x/2^E
编辑:针对 x==0 的情况进行了更改。
有谁知道如何在 R 中执行相同的 MATLAB 函数 [F,E] = log2(X)
?
[F,E] = log2(X) returns arrays F and E such that X=F*2^E. The values in F are typically in the range 0.5 <= abs(F) < 1.
见https://www.mathworks.com/help/matlab/ref/log2.html
For example in MATLAB,
[F,E] = log2(15)
F =
0.9375
E =
4
因此,
F*2^E = 15
我不完全确定你在问什么,但 log2
为你提供了 R 中以 2 为底的对数。例如
log2(2);
#[1] 1
log2(2^10)
#[1] 10
2^(log2(10))
#[1] 10
详情见?log
。
您需要手动计算它们。我不认为有一个内置的来提取它们。试试这个:
x<-15
E <- ifelse(x == 0, 0, floor(log2(abs(x)))+1 )
F<-x/2^E
编辑:针对 x==0 的情况进行了更改。