Content deleted Content added
m →Introduction: WP:CHECKWIKI error fixes using AWB (10093) |
→Simple implementation: cleaned up implementation |
||
Line 55:
<source lang="python">
def gamma(z): # great function from Wiki, but maybe could use memoization?
from cmath import *▼
epsilon = 0.0000001
def withinepsilon(x):
return abs(x - abs(x)) <= epsilon
p = [0.99999999999980993, 676.5203681218851, -1259.1392167224028,▼
771.32342877765313, -176.61502916214059, 12.507343278686905,▼
-0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7]▼
# Reflection formula▼
▲ # Reflection formula
if z.real
return sqrt(2*pi) * t**(z+0.5) * exp(-t) * x▼
for i,_ in enumerate(p):
x += p[i]/(z+i+1)
t = z + len(p) - 0.5
if withinepsilon(result.imag):
return result.real
return result
</source>
|