Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
log2
Base-2 logarithm. Base-2 exponents and mantissae of some decimal numbers
Syntax
y = log2(x) [m, e] = log2(u)
Arguments
- x, y
arrays of decimal or complex numbers, such that
2.^y = x
.- u, m, e
arrays of decimal numbers such that
u = m .* 2.^e
, withsign(m)=sign(u)
and0.5 ≤ abs(m) < 1
.
Description
y = log2(x)
is the "element-wise" base 2 logarithm, with
y(i,j) = log2(x(i,j))
.
log2(-%inf) == %inf + log2(-1) |
[m, e] = log2(u)
computes in an element-wise way the base-2 mantissa
m
and exponent e
of every elements of
u
. Hence, for any index k
we have
u(k) = m(k) .* 2.^e(k)
with 0.5 ≤ |m(k)| < 1
.
|
Examples
Base-2 logarithm:
L = log2([-1, 1, 2, %i, -%i]) clean(2.^L) L = log2([0 %nan %inf]) 2 .^ L L = log2([0 %nan %inf -%inf]) // -%inf<0 turns the result to complex 2 .^ L // -Inf is not retrieved
--> L = log2([-1, 1, 2, %i, -%i]) L = 4.5323601i 0. 1. 2.2661801i -2.2661801i --> clean(2.^L) ans = -1. 1. 2. i -i --> L = log2([0 %nan %inf]) L = -Inf Nan Inf --> 2 .^ L ans = 0. Nan Inf --> L = log2([0 %nan %inf -%inf]) // -%inf<0 turns the result to complex L = -Inf Nan + Nani Inf Inf + 4.5323601i --> 2 .^ L // -Inf is not retrieved ans = 0. Nan + Nani Inf Nan + Nani
Base-2 mantissa + exponent decomposition:
[m, e] = log2([-3, -1.5, -1, 0, 4, 1e20]) m .* 2.^e
--> [m, e] = log2([-3, -1.5, -1, 0, 4, 1e20]) e = 2. 1. 1. 0. 3. 67. m = -0.75 -0.75 -0.5 0. 0.5 0.6776264 --> m .* 2.^e ans = -3. -1.5 -1. 0. 4. 1.000D+20
np = number_properties; x = [%eps np("tiniest") np("tiny") np("huge")] [m, e] = log2(x)
--> x = [%eps np("tiniest") np("tiny") np("huge")] x = 2.220D-16 4.94D-324 2.22D-308 1.79D+308 --> [m, e] = log2(x) e = - 51. - 1073. - 1021. 1024. m = 0.5 0.5 0.5 1.
[m, e] = log2([0 %nan -%inf %inf]) m .* 2.^e
-->[m, e] = log2([0 %nan -%inf %inf]) e = 0. 0. 0. 0. m = 0. Nan - Inf Inf -->m .* 2.^e ans = 0. Nan - Inf Inf
See also
Report an issue | ||
<< log1p | Exponential | logm >> |