function x = benford_cdf_inv ( cdf )

%*****************************************************************************80
%
%% benford_cdf_inv() inverts the Benford CDF.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 November 2022
%
%  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:
%
%    real CDF: the Benford probability that an item taken
%    from a real world distribution will have the initial 
%    digit X or less.
%
%  Output:
%
%    integer X: a value between 1 and 9 for which the cumulative
%    Benford distribution is CDF.
%
  if ( cdf < 0.0 || 1.0 < cdf )
    fprintf ( 1, '\n' );
    fprintf ( 1, '  benford_cdf_inv(): Fatal error!\n' );
    fprintf ( 1, '    0.0 <= cdf <= 1.0 required.\n' );
    fprintf ( 1, '    input value is cdf = %g\n', cdf );
    error ( '  benford_cdf_inv(): Fatal error!\n' );
  end

  x = floor ( 10^cdf );

  return
end

