function cdf = benford_cdf ( x )

%*****************************************************************************80
%
%% benford_cdf() returns the Benford CDF.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    03 March 2016
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Frank Benford,
%    The Law of Anomalous Numbers,
%    Proceedings of the American Philosophical Society,
%    Volume 78, pages 551-572, 1938.
%
%    Ted Hill,
%    The First Digit Phenomenon,
%    American Scientist,
%    Volume 86, July/August 1998, pages 358 - 363.
%
%    Ralph Raimi,
%    The Peculiar Distribution of First Digits,
%    Scientific American,
%    December 1969, pages 109-119.
%
%  Input:
%
%    integer X, the string of significant digits to be checked.
%    If X is 1, then we are asking for the Benford probability that
%    a value will have first digit 1.  If X is 123, we are asking for
%    the probability that the first three digits will be 123, and so on.
%
%  Output:
%
%    real CDF, the Benford probability that an item taken
%    from a real world distribution will have the initial digit X or less.
%
  if ( x <= 0 )
    cdf = 0.0;
  elseif ( i4_is_power_of_10 ( x + 1 ) )
    cdf = 1.0;
  else
    cdf = log10 ( x + 1 );
    cdf = mod ( cdf, 1.0 );
  end

  return
end
