サブ gamma.js Last modified: Mar 25, 2004
function gamma(x)
{
var a, b, z, factor, i, m, mg
if (x > 171.6) {
alert("gamma: Overflow./")
return "Inf"
}
if (x <= 1.5) {
if (x >= 0.5) {
a = x-1.0
factor = 1.0
}
else {
m = Math.floor(x)
a = x-m
if (a == 0) {
alert("gamma: Invalid argument./")
return "Inf"
}
if (a >= -0.5) {
mg = Math.abs(m)+1
}
else {
mg = Math.abs(m)+2
a++
}
z = 1.0
for (i = 0; i < mg; i++) {
z *= x
x++
}
factor = 1.0/z
}
}
else {
m = Math.floor(x)
a = x-m
if (a <= 0.5) {
mg = m-1
}
else {
mg = m
a--
}
z = 1.0
for (i = 0; i < mg; i++) {
z *= (x-1.0)
x--
}
factor = z
}
b = ((((((((-0.42202e-11*a +0.120028e-10)*a +0.923397e-10)*a -0.12736143e-8)*a +0.62756218e-8)*a -0.1595268e-9)*a-0.2054743152e-6)*a +0.13385015466e-5)*a -0.25889950224e-5)*a
b = ((((((((((b -0.175458597517e-4)*a +0.1455961421399e-3)*a -0.3608378162548e-3)*a -0.80432977560424699e-3)*a +0.80232730222673465e-2)*a -0.1764524455014432e-1)*a -0.24552490005400017e-1)*a +0.19109110138769151)*a -0.23309373642178674)*a -0.42278433509846714)*a +1.0
return factor/(1.0+a)/b
}
直前のページへ戻る E-mail to Shigenobu AOKI