20 #define M_PI 3.14159265358979323846
25 #define DBL_MANT_DIG 53
31 #define BIG_CRITERIA (1.0
*(1
<<DBL_MANT_DIG/4
)*(1
<<(DBL_MANT_DIG/2
+1
-DBL_MANT_DIG/4
))) 37 #define SMALL_CRITERIA (1.0
*(1
<<DBL_MANT_DIG/4
)*(1
<<(DBL_MANT_DIG/3
+1
-DBL_MANT_DIG/4
))) 49 x += sqrt((x + 1) * (x - 1));
61 z *= 1 + x2 * (-1.0/6.0 + x2 * 3.0/40.0);
67 z = log(z + sqrt(z * z + 1));
79 z = log(z > 1 ? -1 : (1 + z) / (1 - z)) / 2;
86 return floor(val + 0.5);
96 return (
double(rand()) / RAND_MAX);
100 static unsigned int c = 9;
101 static float lanczos_coefficients[] = {1.000000000000000174663f,
102 5716.400188274341379136f,
103 -14815.30426768413909044f,
104 14291.49277657478554025f,
105 -6348.160217641458813289f,
106 1301.608286058321874105f,
107 -108.1767053514369634679f,
108 2.605696505611755827729f,
109 -0.7423452510201416151527e-2f,
110 0.5384136432509564062961e-7f,
111 -0.4023533141268236372067e-8f
113 float return_val = 0.0f;
116 float temp = z + c + 0.5f;
117 float A = lanczos_coefficients[0];
119 for(i = 1; i < c+2; ++i){
120 A += lanczos_coefficients[i]/(z+i);
122 return_val = sqrt(2 *
M_PI)* pow(temp, z + 0.5f) * exp(-temp) * A;
128 static unsigned int c = 9;
129 static double lanczos_coefficients[] = {1.000000000000000174663,
130 5716.400188274341379136,
131 -14815.30426768413909044,
132 14291.49277657478554025,
133 -6348.160217641458813289,
134 1301.608286058321874105,
135 -108.1767053514369634679,
136 2.605696505611755827729,
137 -0.7423452510201416151527e-2,
138 0.5384136432509564062961e-7,
139 -0.4023533141268236372067e-8
141 double return_val = 0.0;
144 double temp = z + c + 0.5;
145 double A = lanczos_coefficients[0];
147 for(i = 1; i < c+2; ++i){
148 A += lanczos_coefficients[i]/(z+i);
150 return_val = sqrt(2 *
M_PI)* pow(temp, z + 0.5) * exp(-temp) * A;
156 static unsigned int c = 9;
157 static long double lanczos_coefficients[] = {1.000000000000000174663,
158 5716.400188274341379136,
159 -14815.30426768413909044,
160 14291.49277657478554025,
161 -6348.160217641458813289,
162 1301.608286058321874105,
163 -108.1767053514369634679,
164 2.605696505611755827729,
165 -0.7423452510201416151527e-2,
166 0.5384136432509564062961e-7,
167 -0.4023533141268236372067e-8
169 long double return_val = 0.0;
172 long double temp = z + c + 0.5;
173 long double A = lanczos_coefficients[0];
175 for(i = 1; i < c+2; ++i){
176 A += lanczos_coefficients[i]/(z+i);
178 return_val = sqrt(2 *
M_PI)* pow(temp, z + 0.5) * exp(-temp) * A;
189 float a1 = 0.254829592f;
190 float a2 = -0.284496736f;
191 float a3 = 1.421413741f;
192 float a4 = -1.453152027f;
193 float a5 = 1.061405429f;
194 float p = 0.3275911f;
203 float t = 1.0f/(1.0f + p*x);
204 float y = 1.0f - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x);
long double tgammal(long double z)
#define SMALL_CRITERIA_BIT
void srand48(double seed)