program tstinteg (input, output);
{
   This is a test case for the adaptive, recursive numerical integration
   routine integral.  Note that the integrand is singular at x = 0, but
   that the integrator indeed finds the Riemann integral, although the  
   integrator itself is not told of the location of the singularity.  
 
   Compared to most practical problems, this test case is very severe.
}

var
   low,        { lower limit of integration }
   high,       { upper limit of integration }
   eps,        { fractional tolerance on integration }
   ans         { answer }
      : real;
   int_fail    { number of times integration failed to converge }
      : integer;
  
function f(x : real) : real;

   begin {---------------------     f      ------------------------}
      f := 1 / sqrt (abs (x));
   end { f } ;

{$include:'integral.pas'}

begin {-------------------   tstinteg  ------------------------}
   low := -9;
   high := 10000;
   eps := 0.1;
   while eps >= 0.9e-5 do
   begin
      ans := integral (f, low, high, eps, int_fail);
      writeln ('eps=', eps:6, ' int_fail=', int_fail:3, ' ans=', ans:10:5);
      eps := eps * 0.1;
   end;
end { tstinteg } .
