26
26
* MathFunctions is a class of utility methods that implement various mathematical functions.
27
27
*
28
28
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
29
- * @version 2.12 .2021
29
+ * @version 5.13 .2021
30
30
*
31
31
*/
32
32
public final class MathFunctions {
@@ -92,7 +92,7 @@ public static double logGamma(double n) {
92
92
// This check doesn't seem to be necessary given addition of first check in block.
93
93
// if (z == 0.0) return Double.POSITIVE_INFINITY;
94
94
// ln(PI)
95
- final double LOG_PI = 1.14472988584940017414 ;
95
+ final double LOG_PI = 1.1447298858494002 ;
96
96
return LOG_PI - Math .log (z ) - logGamma (n );
97
97
} else if (n < 13.0 ) {
98
98
double z = 1.0 ;
@@ -117,13 +117,13 @@ public static double logGamma(double n) {
117
117
n * evaluatePolynomial (n , POLY_APPROX_2 ) / evaluatePolynomial (n , POLY_APPROX_3 );
118
118
} else {
119
119
// ln(sqrt(2pi))
120
- final double LOG_SQRT_PI2 = 0.91893853320467274178 ;
120
+ final double LOG_SQRT_PI2 = 0.9189385332046727 ;
121
121
double q = (n - 0.5 ) * Math .log (n ) - n + LOG_SQRT_PI2 ;
122
122
if (n > 1.0e8 ) return q ;
123
123
double p = 1.0 / (n * n );
124
124
if (n >= 1000.0 ) {
125
- q = q + ((7.9365079365079365079365e -4 * p - 2.7777777777777777777778e-3 )
126
- * p + 0.0833333333333333333333 ) / n ;
125
+ q = q + ((7.936507936507937E -4 * p - 0.002777777777777778 )
126
+ * p + 0.08333333333333333 ) / n ;
127
127
} else {
128
128
q += evaluatePolynomial (p , STIRLING_EXPANSION_LN_GAMMA ) / n ;
129
129
}
@@ -142,21 +142,22 @@ private static double evaluatePolynomial(double x, double polynomial[]) {
142
142
}
143
143
144
144
private static final double [] STIRLING_EXPANSION_LN_GAMMA = {
145
- 8.11614167470508450300E -4 , -5.95061904284301438324E -4 ,
146
- 7.93650340457716943945E -4 , -2.77777777730099687205E-3 ,
147
- 8.33333333333331927722E-2
145
+ 8.116141674705085E -4 , -5.950619042843014E -4 ,
146
+ 7.936503404577169E -4 , -0.002777777777300997 ,
147
+ 0.08333333333333319
148
148
};
149
149
150
150
private static final double [] POLY_APPROX_2 = {
151
- -1.37825152569120859100E3 , -3.88016315134637840924E4 ,
152
- -3.31612992738871184744E5 , -1.16237097492762307383E6 ,
153
- -1.72173700820839662146E6 , -8.53555664245765465627E5
151
+ -1378.2515256912086 , -38801.631513463784 ,
152
+ -331612.9927388712 , -1162370.974927623 ,
153
+ -1721737.0082083966 , -853555.6642457654
154
154
};
155
155
156
156
private static final double [] POLY_APPROX_3 = {
157
- 1.0 , -3.51815701436523470549E2 , -1.70642106651881159223E4 ,
158
- -2.20528590553854454839E5 , -1.13933444367982507207E6 ,
159
- -2.53252307177582951285E6 , -2.01889141433532773231E6
157
+ 1.0 ,
158
+ -351.81570143652345 , -17064.210665188115 ,
159
+ -220528.59055385445 , -1139334.4436798252 ,
160
+ -2532523.0717758294 , -2018891.4143353277 ,
160
161
};
161
162
162
163
// HELPERS FOR logGamma END HERE
0 commit comments