- 积分
- 881
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-7-27
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 清龙 于 2015-5-21 11:31 编辑
- static class Calc
- {
- static public double NullD = 1e300;
- static public double GammaFun(double x)
- {
- if (x == Math.Floor(x))
- {
- if (x > 0)
- {
- int i = 1;
- for (int j = 2; j < x; j++)
- i *= j;
- return Convert.ToDouble(i);
- }
- }
- else
- {
- double z = 0, r = 0, m = 0;
- if (Math.Abs(x) > 1)
- {
- z = Math.Abs(x);
- m = Math.Floor(x);
- r = 1.0;
- for (int k = 1; k <= m; k++)
- r = r * (z - k);
- z = z - m;
- }
- else
- z = x;
- double[] G = new double[26]{
- 1.0,0.5772156649015329,-0.6558780715202538,
- -0.420026350340952e-1,0.1665386113822915e0,-0.421977345555443e-1,
- -0.96219715278770e-2, 0.72189432466630e-2,
- -0.11651675918591e-2, -0.2152416741149e-3,
- 0.1280502823882e-3, -0.201348547807e-4,
- -0.12504934821e-5, 0.11330272320e-5,
- -0.2056338417e-6, 0.61160950e-8,
- 0.50020075e-8, -0.11812746e-8,
- 0.1043427e-9, 0.77823e-11,
- -0.36968e-11, 0.51e-12,
- -0.206e-13, -0.54e-14,
- 0.14e-14, 0.1e-15};
- double Gr = G[25];
- for (int k = 24; k >= 0; k--)
- Gr = Gr * z + G[k];
- double Ga = 1.0 / (Gr * z);
- if (Math.Abs(x) > 1.0)
- {
- Ga = Ga * r;
- if (x < 0)
- Ga = -1 * Math.PI / (x * Ga * Math.Sin(Math.PI * x));
- }
- return Ga;
- }
- return NullD;
- }
- }
直接调用Calc.GammaFun(x)就出来结果。用的是静态类的写法,像Math类一样 Calc.NullD 表示double类型的缺测数据
|
|