function r8_to_rat_test ( )

%*****************************************************************************80
%
%% r8_to_rat_test() tests r8_to_rat().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    01 July 2021
%
%  Author:
%
%    John Burkardt
%
  ndig = 4;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'r8_to_rat_test():\n' );
  fprintf ( 1, '  r8_to_rat() converts a real number to a rational;\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  The maximum number of digits allowed is %d\n', ndig );

  fprintf ( 1, '\n' );
  fprintf ( 1, '     R   =>  A / B  =>  R2\n' );
  fprintf ( 1, '\n' );

  for i = 1 : 10
    r = rand ( 1, 1 );
    r = 10.0 * ( r - 0.25 );
    [ a, b ] = r8_to_rat ( r, ndig );
    r2 = rat_to_r8 ( a, b );
    fprintf ( 1, '  %10g  %6d  %6d  %10g\n', r, a, b, r2 );
  end

  return
end
