Task

Implement one algorithm (or more) to compute the Gamma (



Γ


{\displaystyle \Gamma }

) function (in the real field only).

If your language has the function as built-in or you know a library which has it, compare your implementation's results with the results of the built-in/library function.

The Gamma function can be defined as:

  



Γ
(
x
)
=


∫

0


∞



t

x
−
1



e

−
t


d
t



{\displaystyle \Gamma (x)=\displaystyle \int _{0}^{\infty }t^{x-1}e^{-t}dt}


This suggests a straightforward (but inefficient) way of computing the 



Γ


{\displaystyle \Gamma }

 through numerical integration.



Better suggested methods:

 Lanczos approximation
 Stirling's approximation


      *FLOAT64
      INSTALL @lib$+"FNUSING"
 
      FOR x = 0.1 TO 2.05 STEP 0.1
        PRINT FNusing("#.#",x), FNusing("##.############", FNgamma(x))
      NEXT
      END
 
      DEF FNgamma(z) = EXP(FNlngamma(z))
 
      DEF FNlngamma(z)
      LOCAL a, b, i%, lz()
      DIM lz(6)
      lz() = 1.000000000190015, 76.18009172947146, -86.50532032941677, \
      \ 24.01409824083091, -1.231739572450155, 0.0012086509738662, -0.000005395239385
      IF z < 0.5 THEN = LN(PI / SIN(PI * z)) - FNlngamma(1.0 - z)
      z -= 1.0
      b = z + 5.5
      a = lz(0)
      FOR i% = 1 TO 6
        a += lz(i%) / (z + i%)
      NEXT
      = (LNSQR(2*PI) + LN(a) - b) + LN(b) * (z+0.5)