Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °
| |
|
|
You are not logged in.
Post a replyTopic review (newest first)
(C.P.R stands for common programming language. C, C++, Java, Python, and more.) Code:if!(is_real(argument))return 0;
var i,k,m,g,ga,gr,r,c,z;
g[0]=1.0;
g[1]=0.5772156649015329;
g[2]=-0.6558780715202538;
g[3]=-0.0420026350340952;
g[4]=0.1665386113822915;
g[5]=-0.0421977345555443;
g[6]=-0.009621971527877;
g[7]=0.007218943246663;
g[8]=-0.0011651675918591;
g[9]=-0.0002152416741149;
g[10]=0.0001280502823882;
g[11]=-0.0000201348547807;
g[12]=-0.0000012504934821;
g[13]=0.000001133027232;
g[14]=-0.0000002056338417;
g[15]=0.000000006116095;
g[16]=0.0000000050020075;
g[17]=-0.0000000011812746;
g[18]=0.0000000001043427;
g[19]=0.0000000000077823;
g[20]=-0.0000000000036968;
g[21]=0.00000000000051;
g[22]=-0.0000000000000206;
g[23]=-0.0000000000000054;
g[24]=0.0000000000000014;
z=argument;
if(z==z div 1){
c=1;
z-=1;
repeat(z-1){
c*=z;
z-=1;
if(z>=9223372036854775808){
show_error("Error in function gamma().",0);
exit;
}
}
return c-(z<=0);
}else{
if(abs(z)>1){
c=abs(z);
m=floor(c);
r=1;
for(k=1;k<=m;k+=1){
r*=(z-k);
}
c-=m;
}else c=z;
gr=g[24];
for(k=23;k>=0;k-=1){
gr*=c;
gr+=g[k];
}
ga=1/(gr*c);
if(abs(z)>1){
ga*=r;
if(z<0)
ga=-pi/(z*ga*sin(pi*z));
}
}
if(ga>=9223372036854775808){
show_error("Error in function gamma().",0);
exit;
}
return ga;It works, but I want to know how. |