function i = vdc_inverse ( r )

%*****************************************************************************80
%
%% vdc_inverse() inverts an element of the van der Corput sequence.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 August 2016
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real R, the I-th element of the van der Corput sequence.
%    |R| < 1.0
%
%  Output:
%
%    Output, integer I, the index of the element of the sequence.
%
  s = sign ( r );
  t = abs ( r );
  if ( 1.0 <= t )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'VDC_INVERSE - Fatal error!\n' );
    fprintf ( 1, '  |R| < 1.0 is required.\n' );
    error ( 'VDC_INVERSE - Fatal error!' );
  end
  i = 0;
  p = 1;

  while ( t ~= 0.0 )
    t = t * 2.0;
    d = t - mod ( t, 1.0 );
    i = i + d * p;
    p = p * 2;
    t = mod ( t, 1.0 );
  end
%
%  Recover the sign.
%
  i = i * s;

  return
end

