clear all
x = 1e8; % try 1e160 > sqrt(realmax)
y = 1e8; % try 1e160 > sqrt(realmax)
disp('acos')
% to be used for |z|>1
% sqrt(1-z*z) = sqrt(1-z)*sqrt(1+z) is useful for VERY large input
% (|z| > sqrt(realmax))
for z = [x,-x,1i*y,-1i*y,x+1i*y,x-1i*y,-x+1i*y,-x-1i*y]
  if (imag(z)==0)
     z = real(z); % otherwise Matlab takes it complex
  end
  if ((isreal(z) && real(z) > 0) || imag(z) < 0)
    tmp = 1/(z-1i*sqrt(1-z)*sqrt(1+z));
  else
    tmp = z+1i*sqrt(1-z)*sqrt(1+z);
  end
  [-1i*log(tmp),acos(z)]
end
disp('asin')
% to be used for |z|>1
% sqrt(1-z*z) = sqrt(1-z)*sqrt(1+z) is useful for VERY large input
% (|z| > sqrt(realmax))
for z = [x,-x,1i*y,-1i*y,x+1i*y,x-1i*y,-x+1i*y,-x-1i*y]
  if (imag(z)==0)
     z = real(z);
  end
  if ((isreal(z) && real(z) > 0) || imag(z) < 0)
    tmp = 1i*z+sqrt(1-z)*sqrt(1+z);
  else
    tmp = -1/(1i*z-sqrt(1-z)*sqrt(1+z));    
  end
  [-1i*log(tmp),asin(z)]
end
disp('acosh')
% to be used for z<0 or complex
% sqrt(1-z*z) = sqrt(1-z)*sqrt(1+z) is useful for VERY large input
% (|z| > sqrt(realmax))
for z = [-x,1i*y,-1i*y,x+1i*y,x-1i*y,-x+1i*y,-x-1i*y]
  if (imag(z)==0)
     z = real(z);
  end
  if ((isreal(z) && real(z) < 0) || (~isreal(z)))
    tmp = z+sqrt(z-1)*sqrt(z+1);
  else
    tmp = 1/(z+sqrt(z-1)*sqrt(z+1));  
  end
  [log(tmp),acosh(z)]
end
disp('asinh')
% to be used for z complex
% sqrt(1-z*z) = sqrt(1-z)*sqrt(1+z) is useful for VERY large input
% (|z| > sqrt(realmax))
for z = [1i*y,-1i*y,x+1i*y,x-1i*y,-x+1i*y,-x-1i*y]
  if (imag(z)==0)
     z = real(z);
  end
  if ((~isreal(z) && real(z) > 0) || ...
      (~isreal(z) && real(z) == 0 && abs(imag(z)) <= 1))
    tmp = z+sqrt(z-1i)*sqrt(z+1i);
  elseif (~isreal(z) && real(z) == 0 && abs(imag(z)) > 1)
    tmp = -1/(z+sqrt(z-1i)*sqrt(z+1i)); % the sign + comes from taking
				% sqrt of complex numbers
  elseif (~isreal(z) && real(z) < 0 && abs(imag(z)) <= 1)
    tmp = -1/(z-sqrt(z-1i)*sqrt(z+1i)); 
  else % real(z) < 0 && abs(imag(z)) > 1
    tmp = -1/(z+sqrt(z-1i)*sqrt(z+1i)); % the sign + comes from taking
				% sqrt of complex numbers
  end  
  [log(tmp),asinh(z)]
end
