pow2
Power of two, or a number scaled by a power of two.
Category: Mathematics > Elementary Math
Syntax
Y = pow2(X)
Returns 2.^X.
Y = pow2(F, E)
Returns F .* 2.^E.
Description
Multiplying by a power of two only changes the exponent of a floating-point number, so pow2(F, E) is exact: no rounding error is introduced. This is why it is used to rebuild a number from a mantissa and exponent. Fractional exponents work as well: pow2(0.5) is sqrt(2).
Input arguments
X- Exponent array.
F, E- Mantissa and exponent arrays of compatible sizes.
Output arguments
Y- Array with the size given by implicit expansion of the inputs.
Example
One and two arguments
pow2(3)
pow2([1 2 3], 2)
pow2(-1)
Output
ans = 8
ans = 1×3
4 8 12
ans = 0.5000