function r = vdc_base ( i, b )

%*****************************************************************************80
%
%% vdc_base() computes an element of the van der Corput sequence in any base.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 August 2016
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer I, the index of the element of the sequence.
%    I = 0 is allowed, and returns R = 0.
%
%    integer B, the base of the sequence.  The standard sequence
%    uses B = 2, and this function expects 2 <= B.
%
%  Output:
%
%    real R, the I-th element of the van der Corput sequence.
%

%
%  2 <= B.
%
  if ( b < 2 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'VDC_BASE - Fatal error!\n' );
    fprintf ( 1, '  2 <= B is required.\n' );
    error ( 'VDC_BASE - Fatal error!' )
  end
%
%  B should be an integer.
%
  b = floor ( b );
%
%  Isolate the sign, and only work with the integer part of I.
%
  s = sign ( i );
  t = abs ( floor ( i ) );
%
%  Carry out the computation.
%
  base_inv = 1.0 / b;

  r = 0.0;

  while ( t ~= 0 )
    digit = mod ( t, b );
    r = r + digit * base_inv;
    base_inv = base_inv / b;
    t = floor ( t / b );
  end
%
%  Recover the sign.
%
  r = r * s;

  return
end

