function value = elliptic_em ( m )

%*****************************************************************************80
%
%% ELLIPTIC_EM evaluates the complete elliptic integral E(M).
%
%  Discussion:
%
%    The value is computed using Carlson elliptic integrals:
%
%      E(m) = RF ( 0, 1-m, 1 ) - 1/3 m RD ( 0, 1-m, 1 ).
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    22 June 2018
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, real M, the argument.
%
%    Output, real VALUE, the function value.
%
  x = 0.0;
  y = 1.0 - m;
  z = 1.0;
  errtol = 1.0E-03;

  [ value1, ierr ] = rf ( x, y, z, errtol );
  if ( ierr ~= 0 )
    fprintf ( 1, 'ELLIPTIC_EM - Fatal error!\n' );
    fprintf ( 1, '  RF returned IERR = %d\n', ierr );
    error ( 'ELLIPTIC_EM - Fatal error!' );
    return
  end

  [ value2, ierr ] = rd ( x, y, z, errtol );
  if ( ierr ~= 0 )
    fprintf ( 1, 'ELLIPTIC_EM - Fatal error!\n' );
    fprintf ( 1, '  RD returned IERR = %d\n', ierr );
    error ( 'ELLIPTIC_EM - Fatal error!' );
    return
  end

  value = value1 - m * value2 / 3.0;

  return
end
