% error_demo1.m
function error_demo1()
  diary('error_demo1_m.out')
  format compact % prevent blank lines
  disp('error_demo1.m running')
  v = zeros(1,3);
  v(1)=1.0;
  v(2)=1.2e-16;
  v(3)=-1.0 % default print
  disp('v=')
  disp(v)
  disp(' ')
  sum = 0.0;
  for i=1:3;
    sum = sum + v(i);
  end;
  disp('loop sum=')
  disp(sum)
  disp('loop should be 1.0 sum*10^16=')
  disp(1.0e+16*sum)
  disp(' ')
  disp('sum = 1.0e16*((1.0+1.2e-16)-1.0)')
  sum = 1.0e16*((1.0+1.2e-16)-1.0)
  disp('sum should be 1.2 with no round off error sum=')
  disp(sum)
  disp(' ')
  disp('sum = 1.0e16*((1.0+1.0e-16)-1.0) # too small!')
  sum=1.0e16*((1.0+1.0e-16)-1.0)
  disp(sum)
  disp(' ')
  disp('error_demo1.m finished') 
  diary off
end
