clear;

a=0.1234
y=mylog(a)
z=log(a)
%..... print results on top of each other
%      to see precision.  The built-in log function should be correct.
%      Chanhe 'precision' variable in the function to see effect.
fprintf('  %30.16f\n  %30.16f \n',y,z);


return;
%  demonstrate rem() function

%b=1;
%for a=3.5:0.3:10
%    r=a-b*fix(a/b);   %  fix rounds down to next lower integer
%    fprintf(' a=%f   b=%d    r=%f  \n',a,b,r);
%end
%return;

%   comparison pitfall:
a=sin(pi)
b=0.0
%  if a == b   %   does not work
if abs(a-b) < 1.0e-10
    disp('they are  equal\n');
else
    disp('not equal\n');
end
return;
    

%.....  tabls of squares
nc=20;
I=1;  sq=1;
while sq < 10000
    sq=I*I;
    %fprintf(' %5d ',sq);
    if rem(I,9) == 0
        %fprintf('\n');
    end
    ic=rem(I-1,nc)+1;   %  code part to store the squares into a matrix
    ir=fix((I-1)/nc)+1;
    A(ic,ir)=sq;
       fprintf(' ic=%d  ir=%d \n',ic,ir);
    I=I+1;
end

A

fprintf('\n');


%  function works now, prints out a lot
function r=mylog(x);

precision=1.0e-13
p=2*precision
x=x-1;
xk=x;  k=1;  s=1;  r=0;
while  p > precision
    rr = s*xk/k
    r=r+rr;
    p=abs(rr);
    xk = xk*x;
    s = -s
    k = k+1
    %  if k==100; break; end;
end

end