next up previous index
Next: A simple FWEB example Up: Caring, Really Caring About Previous: Exercise

   
Annotating Codes with FWEB

 

Consider the following code:

  real(kind=long) function gligf02(a, x)
    real (kind=long), intent(in) :: a, x
    real (kind=long), parameter :: epsilon = 1.0E-9
    real (kind=long) :: a0, b0, a1, b1, r_old, r_new
    integer :: n
    if (x .le. 0.0_long) then
       if (x .lt. 0.0_long) then
          stop 'error: gligf02 called with x < 0'
       else
          gligf02 = glegf02(a)
       end if
    else
       a0 = 0.0_long; b0 = 1.0_long; a1 = 1.0_long; b1 = x
       r_old = a1/b1; delta = r_old
       n = 1
       do while (abs(delta) .gt. abs(epsilon * r_old))
          a0 = a1 + (n - a) * a0; b0 = b1 + (n - a) * b0
          a1 = x * a0 + n * a1; b1 = x * b0 + n * b1
          r_new = a1/b1
          delta = r_new - r_old; r_old = r_new
          n = n + 1
       end do
       gligf02 = r_new * exp(-x + a * log(x))
    end if
  end function gligf02

Even though neatly typed in, this code is thoroughly incomprehensible. There is no way that just by looking at it, you can figure out that it evaluates:

\begin{displaymath}\int_x^\infty e^{-t} t^{a - 1}\,\textrm{d}t
\end{displaymath}



 
next up previous index
Next: A simple FWEB example Up: Caring, Really Caring About Previous: Exercise
Zdzislaw Meglicki
2001-02-26