Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fact(z)
- z=z+1
- local m=math
- local pi,e,f=m.pi,m.exp(1),m.floor
- local g = 7
- local p = {0.99999999999980993, 676.5203681218851, -1259.1392167224028,
- 771.32342877765313, -176.61502916214059, 12.507343278686905,
- -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7}
- if z<0.5 then
- if z<0 and f(z)==z then return m.huge end
- return pi/(m.sin(pi*z)*fact(-z))
- else
- z=z-1
- x=p[1]
- for i=1,g+1 do
- x=x+p[i+1]/(z+i)
- end
- t=z+g+0.5;r=m.sqrt(2*pi)*m.pow(t,z+0.5)*m.exp(-t)*x
- return (f(z)==z) and f(r) or r
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement