38 lines
998 B
Python
38 lines
998 B
Python
import math
|
|
|
|
|
|
def loggam(x):
|
|
# double x0, x2, xp, gl, gl0;
|
|
# long k, n;
|
|
|
|
a = [8.333333333333333e-02, -2.777777777777778e-03,
|
|
7.936507936507937e-04, -5.952380952380952e-04,
|
|
8.417508417508418e-04, -1.917526917526918e-03,
|
|
6.410256410256410e-03, -2.955065359477124e-02,
|
|
1.796443723688307e-01, -1.39243221690590e+00]
|
|
x *= 1.0
|
|
x0 = x
|
|
n = 0
|
|
if x == 1.0 or x == 2.0:
|
|
return 0.0
|
|
|
|
elif x <= 7.0:
|
|
n = int(7 - x)
|
|
x0 = x + n
|
|
x2 = 1.0 / (x0*x0)
|
|
xp = 2 * math.pi
|
|
gl0 = a[9]
|
|
for k in range(8, -1, -1):
|
|
gl0 *= x2
|
|
gl0 += a[k]
|
|
gl = gl0/x0 + 0.5 * math.log(xp) + (x0-0.5) * math.log(x0) - x0
|
|
if x <= 7.0:
|
|
for k in range(1, n + 1):
|
|
gl -= math.log(x0-1.0)
|
|
x0 -= 1.0
|
|
return gl
|
|
|
|
print(loggam(2))
|
|
print(loggam(3))
|
|
print(loggam(4))
|
|
print(loggam(5)) |