function value = r8_csqrt ( x )

%*****************************************************************************80
%
%% r8_csqrt() returns the complex square root of an R8.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    10 February 2015
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real X, the number whose square root is desired.
%
%  Output:
%
%    complex VALUE, the square root of X:
%
  if ( 0.0 < x )
    magnitude = x;
    argument = 0.0;
  elseif ( 0.0 == x )
    magnitude = 0.0;
    argument = 0.0;
  elseif ( x < 0.0 )
    magnitude = -x;
    argument = pi;

  magnitude = sqrt ( magnitude );
  argument = argument / 2.0;

  value = magnitude * ( cos ( argument ) + sin ( argument ) * i );

  return
end
