function value = i4_log2 ( i )

%*****************************************************************************80
%
%% i4_log2() returns the integer part of the logarithm base 2 of I.
%
%  Discussion:
%
%    For positive I4_LOG2(I), it should be true that
%      2^I4_LOG2(X) <= |I| < 2^(I4_LOG2(I)+1).
%    The special case of I4_LOG2(0) returns 0.
%
%  Example:
%
%     I  Value
%
%     0   0
%     1,  0
%     2,  1
%     3,  1
%     4,  2
%     5,  2
%     6,  2
%     7,  2
%     8,  3
%     9,  3
%    10,  3
%   127,  6
%   128,  7
%   129,  7
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 June 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer I: the number whose logarithm base 2 is desired.
%
%  Output:
%
%    integer VALUE: the integer part of the logarithm base 2 of I.
%
  if ( i < 0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'i4_log2(): Fatal error!\n' );
    fprintf ( 1, '  i < 0\n' );
    error ( 'i4_log2(): Fatal error!\n' );
  end

  value = 0;

  while ( 2 <= i )
    i = i / 2;
    value = value + 1;
  end

  return
end
