% Script File: FpFacts
% Prints some facts about the underlying floating point system.

close all
clc

% p = smallest positive integer so 1+1/2^p = 1.
x=1; p=0; y=1; z=x+y;
while z~=x
y=y/2;
p=p+1;
% y = 1/2^p
z=x+y;
end
disp(sprintf('p = %2.0f is the smallest positive integer so 1+1/2^p = 1.',p))

% q = smallest positive integer so 1/2^q = 0.
x=1; q=0;
while x>0
x=x/2;
q=q+1;
end;
disp(sprintf('q = %2.0f is the smallest positive integer so 1/2^q = 0.',q))

% r = smallest positive integer so 2^r = inf.
x=1; r=0;
while x~=inf
x=2*x;
r=r+1;
end
disp(sprintf('r = %2.0f is the smallest positive integer so 2^r = inf.',r))