function errors_test23 ( )

%*****************************************************************************80
%
%% ERRORS_TEST23
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    22 August 2017
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '+=============================================+\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|  Exercise 23                                |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|  Estimate EXP(-5.5) in two ways:            |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|    R1(N) = sum ( I = 0 to N ) X^I/I         |\n' );
  fprintf ( 1, '|    R2(N) = 1 / sum ( I = 0 to N ) (-X)^I/I  |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|  Correct value:                             |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|    EXP(-5.5) = 0.00408677143846406699       |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '+=============================================+\n' );
  fprintf ( 1, '\n' );

  sum2 = 0.0;
  i = 0;
  fac = 1.0;
  x = - 5.5;

  while ( true )

    temp = x ^ i / fac;
    sumold = sum2;
    sum2 = sum2 + temp;
    i = i + 1;
    fac = fac * i;
    temp = sum2 - sumold;

    if ( temp == 0.0 )
      break;
    end

  end

  fprintf ( 1, '  R1 = %20.16g\n', sum2 )

  sum2 = 0.0;
  i = 0;
  fac = 1.0;
  x = 5.5;

  while ( true )

    temp = x ^ i / fac;
    sumold = sum2;
    sum2 = sum2 + temp;
    i = i + 1;
    fac = fac * i;
    temp = sum2 - sumold;

    if ( temp == 0.0 )
      break
    end

  end

  sum2 = 1.0 / sum2;

  fprintf ( 1, '  R2 = %20.16g\n', sum2 )

  return
end
