function [s,n]=segno(z,maxiter,epsilon)
k=1;
delta=epsilon+1;
xout=z;
while ( (k < maxiter) & (delta > epsilon ) )
 k=k+1;
 xin=xout;
 if xin==0 
   xout=0;
   else
   xout=(xin + 1/xin)/2;
  end
delta=abs(xout-xin);
end
n=k;
s=xout;
end
