summaryrefslogtreecommitdiff
path: root/deps/jemalloc/test/include/test/math.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/jemalloc/test/include/test/math.h')
-rw-r--r--deps/jemalloc/test/include/test/math.h95
1 files changed, 45 insertions, 50 deletions
diff --git a/deps/jemalloc/test/include/test/math.h b/deps/jemalloc/test/include/test/math.h
index b057b29a1..efba086dd 100644
--- a/deps/jemalloc/test/include/test/math.h
+++ b/deps/jemalloc/test/include/test/math.h
@@ -1,12 +1,3 @@
-#ifndef JEMALLOC_ENABLE_INLINE
-double ln_gamma(double x);
-double i_gamma(double x, double p, double ln_gamma_p);
-double pt_norm(double p);
-double pt_chi2(double p, double df, double ln_gamma_df_2);
-double pt_gamma(double p, double shape, double scale, double ln_gamma_shape);
-#endif
-
-#if (defined(JEMALLOC_ENABLE_INLINE) || defined(MATH_C_))
/*
* Compute the natural log of Gamma(x), accurate to 10 decimal places.
*
@@ -15,9 +6,8 @@ double pt_gamma(double p, double shape, double scale, double ln_gamma_shape);
* Pike, M.C., I.D. Hill (1966) Algorithm 291: Logarithm of Gamma function
* [S14]. Communications of the ACM 9(9):684.
*/
-JEMALLOC_INLINE double
-ln_gamma(double x)
-{
+static inline double
+ln_gamma(double x) {
double f, z;
assert(x > 0.0);
@@ -31,14 +21,15 @@ ln_gamma(double x)
}
x = z;
f = -log(f);
- } else
+ } else {
f = 0.0;
+ }
z = 1.0 / (x * x);
- return (f + (x-0.5) * log(x) - x + 0.918938533204673 +
+ return f + (x-0.5) * log(x) - x + 0.918938533204673 +
(((-0.000595238095238 * z + 0.000793650793651) * z -
- 0.002777777777778) * z + 0.083333333333333) / x);
+ 0.002777777777778) * z + 0.083333333333333) / x;
}
/*
@@ -50,9 +41,8 @@ ln_gamma(double x)
* Bhattacharjee, G.P. (1970) Algorithm AS 32: The incomplete Gamma integral.
* Applied Statistics 19:285-287.
*/
-JEMALLOC_INLINE double
-i_gamma(double x, double p, double ln_gamma_p)
-{
+static inline double
+i_gamma(double x, double p, double ln_gamma_p) {
double acu, factor, oflo, gin, term, rn, a, b, an, dif;
double pn[6];
unsigned i;
@@ -60,8 +50,9 @@ i_gamma(double x, double p, double ln_gamma_p)
assert(p > 0.0);
assert(x >= 0.0);
- if (x == 0.0)
- return (0.0);
+ if (x == 0.0) {
+ return 0.0;
+ }
acu = 1.0e-10;
oflo = 1.0e30;
@@ -80,7 +71,7 @@ i_gamma(double x, double p, double ln_gamma_p)
gin += term;
if (term <= acu) {
gin *= factor / p;
- return (gin);
+ return gin;
}
}
} else {
@@ -99,23 +90,26 @@ i_gamma(double x, double p, double ln_gamma_p)
b += 2.0;
term += 1.0;
an = a * term;
- for (i = 0; i < 2; i++)
+ for (i = 0; i < 2; i++) {
pn[i+4] = b * pn[i+2] - an * pn[i];
+ }
if (pn[5] != 0.0) {
rn = pn[4] / pn[5];
dif = fabs(gin - rn);
if (dif <= acu && dif <= acu * rn) {
gin = 1.0 - factor * gin;
- return (gin);
+ return gin;
}
gin = rn;
}
- for (i = 0; i < 4; i++)
+ for (i = 0; i < 4; i++) {
pn[i] = pn[i+2];
+ }
if (fabs(pn[4]) >= oflo) {
- for (i = 0; i < 4; i++)
+ for (i = 0; i < 4; i++) {
pn[i] /= oflo;
+ }
}
}
}
@@ -131,9 +125,8 @@ i_gamma(double x, double p, double ln_gamma_p)
* Wichura, M.J. (1988) Algorithm AS 241: The percentage points of the normal
* distribution. Applied Statistics 37(3):477-484.
*/
-JEMALLOC_INLINE double
-pt_norm(double p)
-{
+static inline double
+pt_norm(double p) {
double q, r, ret;
assert(p > 0.0 && p < 1.0);
@@ -142,7 +135,7 @@ pt_norm(double p)
if (fabs(q) <= 0.425) {
/* p close to 1/2. */
r = 0.180625 - q * q;
- return (q * (((((((2.5090809287301226727e3 * r +
+ return q * (((((((2.5090809287301226727e3 * r +
3.3430575583588128105e4) * r + 6.7265770927008700853e4) * r
+ 4.5921953931549871457e4) * r + 1.3731693765509461125e4) *
r + 1.9715909503065514427e3) * r + 1.3314166789178437745e2)
@@ -151,12 +144,13 @@ pt_norm(double p)
2.8729085735721942674e4) * r + 3.9307895800092710610e4) * r
+ 2.1213794301586595867e4) * r + 5.3941960214247511077e3) *
r + 6.8718700749205790830e2) * r + 4.2313330701600911252e1)
- * r + 1.0));
+ * r + 1.0);
} else {
- if (q < 0.0)
+ if (q < 0.0) {
r = p;
- else
+ } else {
r = 1.0 - p;
+ }
assert(r > 0.0);
r = sqrt(-log(r));
@@ -198,9 +192,10 @@ pt_norm(double p)
5.99832206555887937690e-1)
* r + 1.0));
}
- if (q < 0.0)
+ if (q < 0.0) {
ret = -ret;
- return (ret);
+ }
+ return ret;
}
}
@@ -218,9 +213,8 @@ pt_norm(double p)
* Shea, B.L. (1991) Algorithm AS R85: A remark on AS 91: The percentage
* points of the Chi^2 distribution. Applied Statistics 40(1):233-235.
*/
-JEMALLOC_INLINE double
-pt_chi2(double p, double df, double ln_gamma_df_2)
-{
+static inline double
+pt_chi2(double p, double df, double ln_gamma_df_2) {
double e, aa, xx, c, ch, a, q, p1, p2, t, x, b, s1, s2, s3, s4, s5, s6;
unsigned i;
@@ -236,8 +230,9 @@ pt_chi2(double p, double df, double ln_gamma_df_2)
if (df < -1.24 * log(p)) {
/* Starting approximation for small Chi^2. */
ch = pow(p * xx * exp(ln_gamma_df_2 + xx * aa), 1.0 / xx);
- if (ch - e < 0.0)
- return (ch);
+ if (ch - e < 0.0) {
+ return ch;
+ }
} else {
if (df > 0.32) {
x = pt_norm(p);
@@ -263,8 +258,9 @@ pt_chi2(double p, double df, double ln_gamma_df_2)
* (13.32 + 3.0 * ch)) / p2;
ch -= (1.0 - exp(a + ln_gamma_df_2 + 0.5 * ch +
c * aa) * p2 / p1) / t;
- if (fabs(q / ch - 1.0) - 0.01 <= 0.0)
+ if (fabs(q / ch - 1.0) - 0.01 <= 0.0) {
break;
+ }
}
}
}
@@ -273,8 +269,9 @@ pt_chi2(double p, double df, double ln_gamma_df_2)
/* Calculation of seven-term Taylor series. */
q = ch;
p1 = 0.5 * ch;
- if (p1 < 0.0)
- return (-1.0);
+ if (p1 < 0.0) {
+ return -1.0;
+ }
p2 = p - i_gamma(p1, xx, ln_gamma_df_2);
t = p2 * exp(xx * aa + ln_gamma_df_2 + p1 - c * log(ch));
b = t / ch;
@@ -290,11 +287,12 @@ pt_chi2(double p, double df, double ln_gamma_df_2)
s6 = (120.0 + c * (346.0 + 127.0 * c)) / 5040.0;
ch += t * (1.0 + 0.5 * t * s1 - b * c * (s1 - b * (s2 - b * (s3
- b * (s4 - b * (s5 - b * s6))))));
- if (fabs(q / ch - 1.0) <= e)
+ if (fabs(q / ch - 1.0) <= e) {
break;
+ }
}
- return (ch);
+ return ch;
}
/*
@@ -302,10 +300,7 @@ pt_chi2(double p, double df, double ln_gamma_df_2)
* compute the upper limit on the definite integral from [0..z] that satisfies
* p.
*/
-JEMALLOC_INLINE double
-pt_gamma(double p, double shape, double scale, double ln_gamma_shape)
-{
-
- return (pt_chi2(p, shape * 2.0, ln_gamma_shape) * 0.5 * scale);
+static inline double
+pt_gamma(double p, double shape, double scale, double ln_gamma_shape) {
+ return pt_chi2(p, shape * 2.0, ln_gamma_shape) * 0.5 * scale;
}
-#endif