00001
00002
00003
00004
00005
00006 namespace NewGamePhysics.Mathematics
00007 {
00008 using System;
00009
00013 public class Gamma
00014 {
00026 public static double LogFunction(double x)
00027 {
00028 if (x <= 0)
00029 {
00030 throw new ArgumentOutOfRangeException("x");
00031 }
00032
00033 double f;
00034 double y;
00035 double z;
00036
00037 y = x;
00038 if (x < 7.0)
00039 {
00040 f = 1.0;
00041 z = y;
00042 while (z < 7.0)
00043 {
00044 f *= z;
00045 z += 1.0;
00046 }
00047
00048 y = z;
00049 f = -Math.Log(f);
00050 }
00051 else
00052 {
00053 f = 0.0;
00054 }
00055
00056 z = 1.0 / (y * y);
00057
00058 double v =
00059 f + (y - 0.5) * Math.Log(y) - y + 0.918938533204673 +
00060 (((-0.000595238095238 * z + 0.000793650793651) * z - 0.002777777777778) * z + 0.083333333333333) / y;
00061
00062 return v;
00063 }
00064 }
00065 }