%% Floating-Point Number Dissection
% Dissect several numbers into the exponent and mantissa. These operations all follow standard IEEE® arithmetic.
%
% Create a vector X that contains several test values. Calculate the exponent and mantissa for each number.

X = [1 pi -3 eps realmax realmin];
format rat
[F,E] = log2(X)

%
% Collect the results in a table. Convert the numbers into character vectors for display purposes.

x = {'1','pi','-3','eps','realmax','realmin'}';
f = strtrim(cellstr(rats(F')));
T = table(x,f,E','VariableNames',{'Value','Mantissa','Exponent'})

%
% The results indicate that, for the first row, 1=\frac{1}{2}\left(2^1 \right). Similarly, for the fourth row, \textrm{eps}=\frac{1}{2}\left(2^{-51} \right).
% Copyright 2012 The MathWorks, Inc.