@numero-uno-jpn/rstats 0.15.1 → 0.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/README.ja.md +8 -8
  3. package/README.md +8 -8
  4. package/dist/chunks/{chunk-735NNFAS.js → chunk-3THFTB36.js} +2 -2
  5. package/dist/chunks/chunk-3TSWYE5L.js +2 -0
  6. package/dist/chunks/{chunk-7J4HW6VF.js → chunk-3WPU6LGK.js} +2 -2
  7. package/dist/chunks/{chunk-Z3C3G5XI.js → chunk-5ITR67MB.js} +2 -2
  8. package/dist/chunks/chunk-5NRFU6F6.js +2 -0
  9. package/dist/chunks/{chunk-SAZAEPZC.js → chunk-E2LCSVQV.js} +1 -1
  10. package/dist/chunks/chunk-FCNVTIPJ.js +2 -0
  11. package/dist/chunks/chunk-FKAKALOZ.js +2 -0
  12. package/dist/chunks/{chunk-5OSQ76OO.js → chunk-HD73UKPT.js} +2 -2
  13. package/dist/chunks/{chunk-4ILI2FSB.js → chunk-IUULP3LE.js} +1 -1
  14. package/dist/chunks/{chunk-LY2T6DA6.js → chunk-JQG3YQOC.js} +2 -2
  15. package/dist/chunks/chunk-KT66SB7R.js +2 -0
  16. package/dist/chunks/{chunk-IQOVOHZG.js → chunk-MAUAOQG3.js} +2 -2
  17. package/dist/chunks/{chunk-GEJCBCMP.js → chunk-MDYE7QP2.js} +2 -2
  18. package/dist/chunks/{chunk-5SQFDLNG.js → chunk-NM3Z2UBQ.js} +2 -2
  19. package/dist/chunks/{chunk-5XQZNKHZ.js → chunk-PMJI5QO6.js} +2 -2
  20. package/dist/chunks/chunk-UF7KOTHF.js +3 -0
  21. package/dist/chunks/chunk-UOE57JGT.js +2 -0
  22. package/dist/chunks/{chunk-3QTVXDUM.js → chunk-USPEBXSR.js} +2 -2
  23. package/dist/chunks/{chunk-H4CHJMFU.js → chunk-VLUL2HFW.js} +1 -1
  24. package/dist/chunks/{chunk-VOIJKNL2.js → chunk-ZIX7NYQF.js} +1 -1
  25. package/dist/descriptive.js +2 -2
  26. package/dist/distributions/arcsine.js +48 -4
  27. package/dist/distributions/beta.d.ts +1 -1
  28. package/dist/distributions/beta.js +75 -2
  29. package/dist/distributions/cauchy.js +76 -5
  30. package/dist/distributions/exponential.js +16 -2
  31. package/dist/distributions/f.js +143 -24
  32. package/dist/distributions/gamma.d.ts +13 -2
  33. package/dist/distributions/gamma.js +122 -12
  34. package/dist/distributions/geometric.js +19 -3
  35. package/dist/distributions/invgamma.js +60 -10
  36. package/dist/distributions/kumaraswamy.js +116 -17
  37. package/dist/distributions/laplace.js +5 -2
  38. package/dist/distributions/logistic.js +8 -2
  39. package/dist/distributions/lognormal.js +40 -5
  40. package/dist/distributions/nbeta.js +597 -52
  41. package/dist/distributions/nchisq.d.ts +25 -0
  42. package/dist/distributions/nchisq.js +381 -96
  43. package/dist/distributions/negbinomial.js +26 -6
  44. package/dist/distributions/normal.js +29 -1
  45. package/dist/distributions/nt.d.ts +28 -3
  46. package/dist/distributions/nt.js +401 -63
  47. package/dist/distributions/pareto.js +73 -19
  48. package/dist/distributions/t.js +102 -12
  49. package/dist/distributions/triangular.js +93 -27
  50. package/dist/distributions/tukey.js +110 -50
  51. package/dist/distributions/uniform.js +14 -9
  52. package/dist/distributions/weibull.js +65 -10
  53. package/dist/distributions.js +2 -2
  54. package/dist/internal/ddexp.d.ts +13 -0
  55. package/dist/internal/ddexp.js +55 -3
  56. package/dist/internal/discrete.js +30 -7
  57. package/dist/internal/invert.d.ts +5 -0
  58. package/dist/internal/invert.js +59 -5
  59. package/dist/internal/noncentral.d.ts +41 -0
  60. package/dist/internal/noncentral.js +124 -2
  61. package/dist/internal/poissonMixture.d.ts +7 -2
  62. package/dist/internal/poissonMixture.js +142 -38
  63. package/dist/linalg.js +2 -2
  64. package/dist/mixed.js +2 -2
  65. package/dist/numerics.js +2 -2
  66. package/dist/rstats.js +14 -14
  67. package/dist/special/beta.js +7 -0
  68. package/dist/special/dd.d.ts +1 -1
  69. package/dist/special/dd.js +4 -1
  70. package/dist/special/gamma.js +4 -0
  71. package/dist/special/igam.js +126 -21
  72. package/dist/special/incbet.d.ts +10 -0
  73. package/dist/special/incbet.js +218 -48
  74. package/dist/special/incbetLargeA.js +53 -14
  75. package/dist/special/incbetPrefactor.d.ts +57 -0
  76. package/dist/special/incbetPrefactor.js +103 -0
  77. package/dist/special/incbetTemme.js +15 -3
  78. package/dist/special/loader.js +97 -22
  79. package/dist/special.js +2 -2
  80. package/dist/tests.js +2 -2
  81. package/package.json +1 -1
  82. package/dist/chunks/chunk-5YMP4WAJ.js +0 -2
  83. package/dist/chunks/chunk-BDJPSEA7.js +0 -2
  84. package/dist/chunks/chunk-KO6QQPC6.js +0 -2
  85. package/dist/chunks/chunk-OLPTFKIZ.js +0 -3
  86. package/dist/chunks/chunk-TYFGVCVQ.js +0 -2
  87. package/dist/chunks/chunk-UWBYDIOH.js +0 -2
  88. package/dist/chunks/chunk-UZHY5DWN.js +0 -2
@@ -0,0 +1,103 @@
1
+ // The factor x^a (1-x)^b / B(a, b) in front of the series, continued fractions and expansions of the incomplete beta
2
+ // function (incbet.ts, incbetLargeA.ts) where Loader's binomial form (loader.ts), used elsewhere, loses digits: when one
3
+ // shape is small, or one is huge and the other moderate. Derived from Γ(1 + s) = s Γ(s) and Stirling's series.
4
+ import { ddAdd, ddLog, ddMulNum, ddNeg, ddSub } from "./dd.js";
5
+ import { gamma, lgamma1p } from "./gamma.js";
6
+ import { lgammaDiff, lgammaDiffDD } from "./lgammaDiff.js";
7
+ /**
8
+ * Below this smaller shape the prefactor is formed by the small-shape form of prefactorParts. Loader's stirlerr of a
9
+ * shape s < 1 is lgamma1p(s) - (s + 1/2) log s + ..., whose rounding (absolute, about ε |log s| / 2) cancels against the
10
+ * log of the denominator: the prefactor was off by 2e-15 to 1e-14 relative for shapes from 1e-8 to 1e-30 (2e-14 at
11
+ * 1e-130: pbeta(1.08e-285, 1.56e-130, 2) was 1.0000000000000195). Against mpmath, the small-shape form was within 4e-16
12
+ * for smaller shapes from 1e-30 to 0.3 (Loader's 1.5e-15), and from 0.3 to 1 within 1.3e-15 with an rms error of
13
+ * 2.6e-16 (Loader's 1.1e-15 and 3.8e-16); from 1 on Loader's form is the better one where both shapes grow. Up to 1
14
+ * rather than 0.3: tails of a moderate shape from both forms disagreed by 1.6e-15 (pnbinom(0, 0.818, { prob: 0.0821 })
15
+ * and its upper tail), enough to move qnbinom of that upper tail to 1
16
+ */
17
+ export const SMALL_SHAPE = 1;
18
+ /**
19
+ * From this larger shape on (with the smaller one at most HUGE_SHAPE_MAX_SMALL), the huge-shape form of
20
+ * prefactorParts. Loader's form was off by up to 2e-14 relative from 1e15 on and 8e-14 near 1e300 (against mpmath, the
21
+ * smaller shape from 1e-3 to 40 and 1 - x around it divided by the larger: pbeta(5.6e-161, 0.82, 1.5e160) and its
22
+ * upper tail added up to 1 + 3e-14); the huge-shape form stayed within 3.4e-15 from 1e15 on (the rounding of Γ(s)),
23
+ * but neglects terms of order s³/l² (see lgammaRatioHuge), which matter below about 1e10
24
+ */
25
+ export const HUGE_SHAPE = 2 ** 52;
26
+ /** Largest smaller shape for the huge-shape form (Γ(s) is finite and accurate to a few ulps up to there) */
27
+ export const HUGE_SHAPE_MAX_SMALL = 100;
28
+ /**
29
+ * x^a (1-x)^b / B(a, b) = c exp(e) as [c, e] (e in double-double) where Loader's form loses digits: for
30
+ * min(a, b) < SMALL_SHAPE, or max(a, b) >= HUGE_SHAPE with min(a, b) <= HUGE_SHAPE_MAX_SMALL; undefined elsewhere.
31
+ * With s = min(a, b), l = max(a, b):
32
+ * - small shape: 1/B(a, b) = ab/(a + b) Γ(1+a+b)/(Γ(1+a) Γ(1+b)), c = ab/(a + b) = s/(1 + s/l) (no underflow of the
33
+ * product ab), and the log of the ratio of gamma functions from smallShapeG, of the size of s log l or less
34
+ * - huge shape: 1/B(a, b) = Γ(l + s)/(Γ(l) Γ(s)), c = 1/Γ(s), and log Γ(l + s) - log Γ(l) from lgammaRatioHuge
35
+ * a log x and b log(1-x) are formed in double-double (b log(1-x) can be large), each logarithm from the smaller of x and
36
+ * 1 - x: x may have rounded to 1 even in double-double (pf(2.5e-97, 1.7e80, 2.7e-95) passes 1 - x = 6.3e-79 with
37
+ * x = [1, 0]), and a log x, about -a (1 - x), then still matters for a huge a
38
+ */
39
+ export function prefactorParts(a, b, x, xc) {
40
+ const s = Math.min(a, b);
41
+ const l = Math.max(a, b);
42
+ let c;
43
+ let g;
44
+ if (s < SMALL_SHAPE) {
45
+ c = s / (1 + s / l);
46
+ g = smallShapeG(a, b);
47
+ }
48
+ else if (l >= HUGE_SHAPE && s <= HUGE_SHAPE_MAX_SMALL) {
49
+ c = 1 / gamma(s);
50
+ g = lgammaRatioHuge(s, l);
51
+ }
52
+ else {
53
+ return undefined;
54
+ }
55
+ const lx = x[0] <= 0.5 ? ddLog(x) : log1m(xc);
56
+ const lxc = xc[0] <= 0.5 ? ddLog(xc) : log1m(x);
57
+ const ta = mulBig(lx, a);
58
+ const tb = mulBig(lxc, b);
59
+ // (both terms are at most 0; where one overflows the exponent is -Infinity, which the double-double sums made NaN:
60
+ // pbeta(0.998, 55.1, 6.3e307) was NaN)
61
+ if (!Number.isFinite(ta[0]) || !Number.isFinite(tb[0]))
62
+ return [c, [ta[0] + tb[0], 0]];
63
+ return [c, ddAdd(ddAdd(ta, tb), g)];
64
+ }
65
+ /**
66
+ * log Γ(l + s) - log Γ(l) in double-double for l >= HUGE_SHAPE and s <= HUGE_SHAPE_MAX_SMALL. From Stirling's series,
67
+ * log Γ(l + s) - log Γ(l) = s log l + [(l + s - 1/2) log1p(s/l) - s] + [stirlerr(l + s) - stirlerr(l)]
68
+ * = s log l + s (s - 1) / (2 l) + O(s³/l²)
69
+ * (the stirlerr terms differ by about -s/(12 l²)); the neglected terms are below 1e-25 here. s log l is formed in
70
+ * double-double. lgammaDiff loses s itself where s/l underflows (it forms (l - 1/2) log1p(s/l) - s, which is then -s, not
71
+ * about 0): pbeta(2.2e-292, 2.4e-69, 4.5e290, { lowerTail: false }) was 6.87e-69, 4.44e-69 expected
72
+ */
73
+ export function lgammaRatioHuge(s, l) {
74
+ return ddAdd(mulBig(ddLog([l, 0]), s), [(s * (s - 1)) / (2 * l), 0]);
75
+ }
76
+ /**
77
+ * log Γ(1+a+b)/(Γ(1+a) Γ(1+b)) for min(a, b) < SMALL_SHAPE (see prefactorParts), with s = min(a, b), l = max(a, b), as
78
+ * [lgamma(1+l+s) - lgamma(1+l)] - lgamma1p(s), or for l >= 1 with Γ(1+s+l)/Γ(1+l) = (s + l)/l Γ(s+l)/Γ(l). Each term
79
+ * is of the size of s (log l) and accurate relative to that: the result is about s (ψ(1+l) + γ), and where it decides
80
+ * 1 - I_x(a, b) = -expm1(...) it must be (with lgamma1p(a + b) for the first term, a + b dropped s at s = 5.9e-87,
81
+ * b = 0.0845, and pf(1e300, 0.169, 1.18e-86) came out 1.5e-4 too large). For l >= HUGE_SHAPE, lgamma(s+l) - lgamma(l)
82
+ * from lgammaRatioHuge (lgammaDiff loses s where s/l underflows)
83
+ */
84
+ export function smallShapeG(a, b) {
85
+ const s = Math.min(a, b);
86
+ const l = Math.max(a, b);
87
+ if (l < 1)
88
+ return [lgammaDiff(s, 1 + l) - lgamma1p(s), 0];
89
+ return ddAdd(l >= HUGE_SHAPE ? lgammaRatioHuge(s, l) : lgammaDiffDD(s, l), [Math.log1p(s / l) - lgamma1p(s), 0]);
90
+ }
91
+ /** log(1 - y) in double-double (0 <= y <= 1/2); below 1e-15, -(y + y^2/2) (the next term is below 1e-30 relative) */
92
+ function log1m(y) {
93
+ return y[0] < 1e-15 ? ddNeg(ddAdd(y, [(y[0] * y[0]) / 2, 0])) : ddLog(ddSub([1, 0], y));
94
+ }
95
+ /**
96
+ * x a in double-double, also for a above 1e290 (where the splitting of a in ddMulNum would overflow); [±Infinity, 0]
97
+ * where the product overflows (the scaling back made it NaN)
98
+ */
99
+ export function mulBig(x, a) {
100
+ if (!Number.isFinite(x[0] * a))
101
+ return [x[0] * a, 0];
102
+ return a > 1e290 ? ddMulNum(ddMulNum(x, a / 2 ** 64), 2 ** 64) : ddMulNum(x, a);
103
+ }
@@ -153,6 +153,16 @@ function erfcxMinusLeading(y) {
153
153
  t = (-k * (k + 0.5)) / (z + 2 * k + 1.5 + t);
154
154
  return -1 / (4 * SQRT_PI * y * (z + 1.5 + t));
155
155
  }
156
+ /**
157
+ * r x in double-double for r up to the largest double: above 1e299 the splitting in the product overflows, so r is
158
+ * scaled by 2^-64 (exactly) and the product back (pbeta(0.5, 6e299, 6e299) was Infinity)
159
+ */
160
+ function mulLarge(r, x) {
161
+ if (!(r[0] > 1e299))
162
+ return ddMul(r, x);
163
+ const p = ddMul([r[0] * 2 ** -64, r[1] * 2 ** -64], x);
164
+ return [p[0] * 2 ** 64, p[1] * 2 ** 64];
165
+ }
156
166
  /**
157
167
  * I_x(a, b) (lower) or 1 - I_x(a, b) by the uniform asymptotic expansion, as [log, linear] (log NaN unless
158
168
  * wantLog). x and 1 - x are given in double-double. Returns undefined outside the region where the expansion is
@@ -161,7 +171,9 @@ function erfcxMinusLeading(y) {
161
171
  export function betaIncTemme(a, b, xd, xcd, lower, wantLog) {
162
172
  const rr = twoSum(a, b);
163
173
  const r = rr[0];
164
- const m = (a * b) / r;
174
+ // (a b overflows beyond 1.8e308: then a (b / r))
175
+ const ab = a * b;
176
+ const m = Number.isFinite(ab) ? ab / r : a * (b / r);
165
177
  if (!(m >= TEMME_MIN_M) || !Number.isFinite(r))
166
178
  return undefined;
167
179
  const p = a / r;
@@ -172,11 +184,11 @@ export function betaIncTemme(a, b, xd, xcd, lower, wantLog) {
172
184
  if (Math.abs(x - p) > 2 * pq)
173
185
  return undefined;
174
186
  // r x - a exactly enough (sign of x - p, and g_0 in the tail form)
175
- const rx = ddMul(rr, xd);
187
+ const rx = mulLarge(rr, xd);
176
188
  const dx = ddSub(rx, [a, 0]);
177
189
  const d = dx[0] + dx[1];
178
190
  // E = bd0(a, r x) + bd0(b, r (1 - x)) in double-double
179
- const e = ddAdd(bd0dd(a, rx), bd0dd(b, ddMul(rr, xcd)));
191
+ const e = ddAdd(bd0dd(a, rx), bd0dd(b, mulLarge(rr, xcd)));
180
192
  const E = e[0] + e[1];
181
193
  const tau2 = (2 * E) / m;
182
194
  if (!(tau2 <= TAU_MAX * TAU_MAX))
@@ -70,6 +70,12 @@ const TAIL_IN_DOUBLE = 0.12;
70
70
  * When x and M are close, it is computed by the series in v = (x - M)/(x + M) (Loader 2000).
71
71
  */
72
72
  export function bd0dd(x, M) {
73
+ // bd0 is homogeneous of degree 1: from about 1e300 the splitting in the double-double products overflows (x + M
74
+ // enters them), so scale x and M by 2^-64 (exactly, unless the smaller one would become subnormal; its quotient is
75
+ // then far out and the logarithms are taken separately below) and the result back (pgamma(9.9e299, 1e300) was NaN)
76
+ if (Math.max(x, M[0]) > 1e299 && Math.min(x, M[0]) > 1e-250) {
77
+ return scaleUp(bd0dd(x * 2 ** -64, [M[0] * 2 ** -64, M[1] * 2 ** -64]));
78
+ }
73
79
  if (!isDoubleDouble())
74
80
  return bd0ddOps(x, M);
75
81
  // d = x - M and the series expand the same operations as bd0ddOps below, in the same order, without allocating arrays
@@ -342,10 +348,11 @@ export function bd0dd(x, M) {
342
348
  return [sh, sl];
343
349
  }
344
350
  // x log(x/M) + (M - x), with log(x/M) from the double-double quotient (one logarithm instead of two) unless the
345
- // quotient leaves the normal range, where its low part would be lost
351
+ // quotient leaves the normal range, where its low part would be lost, or x or M is above 1e300, where the splitting
352
+ // of the double-double division overflows (dgamma(9.3e281, 1.9e183, { rate: 3e21 }) threw a TypeError)
346
353
  const ratio = x / M[0];
347
- const lr = ratio > 1e-290 && ratio < 1e290 ? ddLog(ddDiv([x, 0], M)) : ddSub(ddLog([x, 0]), ddLog(M));
348
- return ddAdd(ddMulNum(lr, x), [-dh, -dl]);
354
+ const lr = ratio > 1e-290 && ratio < 1e290 && Math.max(x, M[0]) < 1e300 ? ddLog(ddDiv([x, 0], M)) : ddSub(ddLog([x, 0]), ddLog(M));
355
+ return farDeviance(lr, x, [dh, dl]);
349
356
  }
350
357
  /** bd0dd written with calls to the double-double helpers (used when evaluating in double-precision mode; see src/special/dd.ts) */
351
358
  function bd0ddOps(x, M) {
@@ -367,8 +374,41 @@ function bd0ddOps(x, M) {
367
374
  }
368
375
  // x log(x/M) + (M - x)
369
376
  const ratio = x / M[0];
370
- const lr = ratio > 1e-290 && ratio < 1e290 ? ddLog(ddDiv([x, 0], M)) : ddSub(ddLog([x, 0]), ddLog(M));
371
- return ddAdd(ddMulNum(lr, x), ddNeg(d));
377
+ const lr = ratio > 1e-290 && ratio < 1e290 && Math.max(x, M[0]) < 1e300 ? ddLog(ddDiv([x, 0], M)) : ddSub(ddLog([x, 0]), ddLog(M));
378
+ return farDeviance(lr, x, d);
379
+ }
380
+ /**
381
+ * x lr - d for lr = log(x/M) and d = x - M (the far branch of bd0dd). Above 1e299 the splitting of x in the product
382
+ * overflows (pgamma(1e-300, 1e301) was NaN, where M is too small for the scaling at the top of bd0dd): the product and
383
+ * d are then taken times 2^-64 (exactly) and the sum scaled back, Infinity where that overflows
384
+ */
385
+ function farDeviance(lr, x, d) {
386
+ if (x < 1e299)
387
+ return ddAdd(ddMulNum(lr, x), ddNeg(d));
388
+ return scaleUp(ddAdd(ddMulNum(lr, x * 2 ** -64), [-d[0] * 2 ** -64, -d[1] * 2 ** -64]));
389
+ }
390
+ /**
391
+ * A deviance computed times 2^-64, scaled back; [Infinity, 0] where it overflows (a finite low part beside it made
392
+ * the sums of its callers NaN: dgamma(1.3e27, 9.2e305, rate 0.44) was NaN)
393
+ */
394
+ function scaleUp(r) {
395
+ const hi = r[0] * 2 ** 64;
396
+ return Number.isFinite(hi) ? [hi, r[1] * 2 ** 64] : [hi, 0];
397
+ }
398
+ /**
399
+ * bd0(x, n p) with n and p in double-double. Above 1e299 the splitting in the double-double product overflows, so n is
400
+ * scaled by 2^-64 there (exactly) and the product back. Where n p is not a normal number well inside the range (below
401
+ * 1e-290, down to 0 by underflow, as with tiny shapes: pbeta(5.8e-295, 2.8e-193, 3.5e-153) threw a TypeError), its
402
+ * logarithm is taken as log n + log p
403
+ */
404
+ function bd0Prod(x, nn, p) {
405
+ const s = nn[0] > 1e299 ? 2 ** -64 : 1;
406
+ const ms = ddMul([nn[0] * s, nn[1] * s], p);
407
+ const M = [ms[0] / s, ms[1] / s];
408
+ if (M[0] >= 1e-290)
409
+ return bd0dd(x, M);
410
+ const lr = ddSub(ddLog([x, 0]), ddAdd(ddLog(nn), ddLog(p)));
411
+ return ddAdd(ddMulNum(lr, x), twoSum(nn[0] * p[0], -x));
372
412
  }
373
413
  /** Double-precision version of bd0 */
374
414
  export function bd0(x, M) {
@@ -385,12 +425,29 @@ function expNegDD(e, log, logDenom, denom) {
385
425
  return -e[0] - e[1] - 0.5 * logDenom();
386
426
  if (e[0] < 700)
387
427
  return (Math.exp(-e[0]) * (1 - e[1])) / Math.sqrt(denom());
428
+ // Far below the subnormals; e[1] can then exceed 1 (it is up to half an ulp of e[0]) and 1 - e[1] would give -0
429
+ if (e[0] > 2000)
430
+ return 0;
388
431
  // Region where the result is near subnormal: multiply by exp(-700) last so that rounding happens once, at the end
389
432
  const d = denom();
390
433
  if (!Number.isFinite(d) || d === 0)
391
434
  return Math.exp(-e[0] - e[1] - 0.5 * logDenom());
392
435
  return ((Math.exp(700 - e[0]) * (1 - e[1])) / Math.sqrt(d)) * Math.exp(-700);
393
436
  }
437
+ /**
438
+ * n v for a double-double n that may exceed 1e299, where the splitting in ddMul overflows (dnbinom(0, 2.4e301, { prob:
439
+ * 1 - 2.3e-11 }) was NaN): n is then scaled by 2^-64 (exactly) and the product back
440
+ */
441
+ function mulLarge(nn, v) {
442
+ if (!(nn[0] > 1e299))
443
+ return ddMul(nn, v);
444
+ return scaleUp(ddMul([nn[0] * 2 ** -64, nn[1] * 2 ** -64], v));
445
+ }
446
+ /**
447
+ * exp of a double-double log probability; 0 far below the subnormals, where the low part can exceed 1 and the first
448
+ * order correction would give -0
449
+ */
450
+ const expLogDD = (l) => (l[0] < -2000 ? 0 : Math.exp(l[0]) * (1 + l[1]));
394
451
  /**
395
452
  * Binomial probability C(n, x) p^x q^(n-x). x and n need not be integers (used by the beta and F distributions).
396
453
  * The caller passes q = 1 - p accurately.
@@ -425,26 +482,25 @@ export function dbinomRawDD(x, nmx, p, q, log) {
425
482
  return one;
426
483
  if (p[0] < 0.1) {
427
484
  // n log q = -bd0(n, n q) - n p
428
- const e = ddAdd(bd0dd(n, ddMul(nn, q)), ddMul(nn, p));
429
- return log ? -e[0] - e[1] : Math.exp(-e[0]) * (1 - e[1]);
485
+ const e = ddAdd(bd0Prod(n, nn, q), mulLarge(nn, p));
486
+ return log ? -e[0] - e[1] : expLogDD([-e[0], -e[1]]);
430
487
  }
431
488
  const lq = ddLog(q);
432
- const lc = ddMul(nn, lq);
433
- return log ? lc[0] + lc[1] : Math.exp(lc[0]) * (1 + lc[1]);
489
+ const lc = mulLarge(nn, lq);
490
+ return log ? lc[0] + lc[1] : expLogDD(lc);
434
491
  }
435
492
  if (nmx === 0) {
436
493
  if (q[0] < 0.1) {
437
- const e = ddAdd(bd0dd(n, ddMul(nn, p)), ddMul(nn, q));
438
- return log ? -e[0] - e[1] : Math.exp(-e[0]) * (1 - e[1]);
494
+ const e = ddAdd(bd0Prod(n, nn, p), mulLarge(nn, q));
495
+ return log ? -e[0] - e[1] : expLogDD([-e[0], -e[1]]);
439
496
  }
440
- const lc = ddMul(nn, ddLog(p));
441
- return log ? lc[0] + lc[1] : Math.exp(lc[0]) * (1 + lc[1]);
497
+ const lc = mulLarge(nn, ddLog(p));
498
+ return log ? lc[0] + lc[1] : expLogDD(lc);
442
499
  }
443
500
  if (x < 0 || nmx < 0)
444
501
  return zero;
445
502
  // E = stirlerr(x) + stirlerr(n-x) - stirlerr(n) + bd0(x, np) + bd0(n-x, nq)
446
- let e = ddAdd(bd0dd(x, ddMul(nn, p)), bd0dd(nmx, ddMul(nn, q)));
447
- e = ddAdd(e, twoSum(stirlerr(x) + stirlerr(nmx), -stirlerr(n)));
503
+ const e = binomialExponent(x, nmx, nn, p, q);
448
504
  // Denominator 2 pi x (n - x) / n
449
505
  return expNegDD(e, log, () => LN_2PI + Math.log(x) + Math.log(nmx) - Math.log(n), () => 2 * Math.PI * x * (nmx / n));
450
506
  }
@@ -455,9 +511,18 @@ export function dbinomRawDD(x, nmx, p, q, log) {
455
511
  export function dbinomExponent(x, nmx, p, q) {
456
512
  const nn = twoSum(x, nmx);
457
513
  const n = nn[0];
458
- let e = ddAdd(bd0dd(x, ddMul(nn, p)), bd0dd(nmx, ddMul(nn, q)));
459
- e = ddAdd(e, twoSum(stirlerr(x) + stirlerr(nmx), -stirlerr(n)));
460
- return { e, logDenom: LN_2PI + Math.log(x) + Math.log(nmx) - Math.log(n) };
514
+ return { e: binomialExponent(x, nmx, nn, p, q), logDenom: LN_2PI + Math.log(x) + Math.log(nmx) - Math.log(n) };
515
+ }
516
+ /**
517
+ * The exponent E = bd0(x, np) + bd0(n - x, nq) + stirlerr(x) + stirlerr(n - x) - stirlerr(n) in double-double;
518
+ * [Infinity, 0] where a deviance overflows (the double-double sums made it NaN: dbeta(0.998, 55.1, 6.3e307))
519
+ */
520
+ function binomialExponent(x, nmx, nn, p, q) {
521
+ const d1 = bd0Prod(x, nn, p);
522
+ const d2 = bd0Prod(nmx, nn, q);
523
+ if (!Number.isFinite(d1[0] + d2[0]))
524
+ return [Infinity, 0];
525
+ return ddAdd(ddAdd(d1, d2), twoSum(stirlerr(x) + stirlerr(nmx), -stirlerr(nn[0])));
461
526
  }
462
527
  /** Poisson probability lambda^x e^-lambda / x!. x need not be an integer (used by the gamma distribution). */
463
528
  export function dpoisRaw(x, lambda, log) {
@@ -479,11 +544,21 @@ function dpoisRawCore(x, lambda, wantLog, wantLin) {
479
544
  if (lambda < x * DBL_MIN) {
480
545
  if (!Number.isFinite(x))
481
546
  return [-Infinity, 0];
482
- const v = -lambda + x * Math.log(lambda) - lgamma1p(x);
547
+ // (lgamma1p(x) overflows from about 2.5e305 on, where x log(lambda) may too: the log is -Infinity, not NaN)
548
+ const lg = lgamma1p(x);
549
+ const v = lg === Infinity ? -Infinity : -lambda + x * Math.log(lambda) - lg;
483
550
  return [v, wantLin ? Math.exp(v) : NaN];
484
551
  }
485
- const e = ddAdd(bd0dd(x, [lambda, 0]), [stirlerr(x), 0]);
552
+ const b = bd0dd(x, [lambda, 0]);
553
+ // (an overflowed deviance stays [Infinity, 0]: the double-double sum would make it NaN)
554
+ const e = b[0] === Infinity ? b : ddAdd(b, [stirlerr(x), 0]);
486
555
  const logDenom = () => LN_2PI + Math.log(x);
487
- const denom = () => 2 * Math.PI * x;
488
- return [wantLog ? expNegDD(e, true, logDenom, denom) : NaN, wantLin ? expNegDD(e, false, logDenom, denom) : NaN];
556
+ // 2 pi x overflows above about 2.9e307: the linear value is then taken with pi x / 8 and divided by 4 (it was 0 where
557
+ // dchisq(1e308, 1e308) is 2.8e-155)
558
+ const big = x > 2e307;
559
+ const denom = big ? () => (Math.PI / 8) * x : () => 2 * Math.PI * x;
560
+ return [
561
+ wantLog ? expNegDD(e, true, logDenom, denom) : NaN,
562
+ wantLin ? expNegDD(e, false, logDenom, denom) / (big ? 4 : 1) : NaN,
563
+ ];
489
564
  }
package/dist/special.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! rStats.js 0.15.1 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
- import{a as wt,b as Lt,c as _t,d as Et}from"./chunks/chunk-5SQFDLNG.js";import{c as G,d as St,e as jt,j as ht}from"./chunks/chunk-BDJPSEA7.js";import{A as v,C as Dt,D as Ft,b as $,c as qt,h as ft,k as d,l as q,m as U,n as _,o as C,p as Z,q as ct,u as z,v as lt,w as mt,y as ut}from"./chunks/chunk-UZHY5DWN.js";import{b as E,d as j,f as T,g as J,h as at,i as O,k as L}from"./chunks/chunk-UWBYDIOH.js";var Mt=22250738585072014e-324;function W(t,e,n){if(t<10)return Math.pow(e/2,t)/q(t+1)*n;let s=e/2,r=z(t,s,!1);if(r>=Mt&&s<700){let a=r*Math.exp(s)*n;if(Math.abs(a)>=Mt)return a}let o=z(t,s,!0)+s+Math.log(Math.abs(n));return Math.sign(n)*Math.exp(o)}var D=Number.EPSILON,H=1e6;function pt(t){return Math.expm1(C(t))}function Tt(t,e){let n=pt(t),s=pt(-t),r=Math.log(e/2),o=Math.exp(t*r),a=-r*t,i=Math.abs(t)<D?1:d(t)/(t*Math.PI),c=Math.abs(a)<D?1:Math.sinh(a)/a,l=Math.abs(t)<D?-.5772156649015329:.5/t*(n-s)*i,f=(2+n+s)*i/2,m=(n+1)/(2*o),u=(1+s)*o/2,M=(Math.cosh(a)*l+c*-r*f)/i,p=m,h=1,S=h*M,k=h*p;for(let I=1;I<H&&(M=(I*M+m+u)/(I*I-t*t),m/=I-t,u/=I+t,p=m-I*M,h*=e*e/(4*I),S+=h*M,k+=h*p,!(Math.abs(h*M)<Math.abs(S)*D));I++);return[S,2*k/e]}function At(t,e){let n=Math.sqrt(Number.MIN_VALUE*4503599627370496),s=n,r=n,o=0;for(let a=1;a<H;a++){let i=2*(t+a)/e;s=i+1/s,o=i+o,s===0&&(s=n),o===0&&(o=n),o=1/o;let c=s*o;if(r*=c,Math.abs(c-1)<=2*D)break}return r}function Jt(t,e){let n=t*t-.25,s=2*(e+1),r=1/s,o=r,a=r,i=0,c=1,l=-n,f=l,m=1+f*a;for(let p=2;p<H;p++){n-=2*(p-1),s+=2,r=1/(s+n*r),a*=s*r-1,o+=a;let h=(i-(s-2)*c)/n;if(i=c,c=h,l*=-n/p,f+=l*h,m+=f*a,h<D&&(l*=h,i/=h,c/=h),Math.abs(f*a)<Math.abs(m)*D)break}let u=(.5+t+e+(t*t-.25)*o)/e,M=Math.sqrt(Math.PI/(2*e))/m;return[M,M*u]}function V(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function bt(t,e){let n=Math.round(t),s=t-n,r,o;if(s===-.5)r=o=Math.sqrt(Math.PI/(2*e));else if(e<=2){let[i,c]=Tt(s,e),l=Math.exp(e);r=i*l,o=c*l}else[r,o]=Jt(s,e);let a=0;for(let i=1;i<=n;i++){let c=2*(s+i)/e,l=Math.log2(Math.abs(o))+Math.log2(c);if(l>900&&Number.isFinite(l)){let m=Math.ceil(l-800);r=V(r,-m),o=V(o,-m),a+=m}let f=c*o+r;r=o,o=f}return{k:r,k1:o,exp2:a}}function Kt(t,e){let n=e*e/4,s=1,r=0;for(let o=1;o<H&&(r+=s,s*=n/o,s/=o+t,!(Math.abs(s)<=D*Math.abs(r)));o++);return W(t,e,r+s)}function Rt(t,e,n){if(t===0||!Number.isFinite(t))return t;let s=t,r=e,o=n>0?700:-700,a=Math.exp(o);for(;Math.abs(n)>700;){n-=o,s*=a;let i=Math.floor(Math.log2(Math.abs(s)));s=V(s,-i),r+=i}return V(s*Math.exp(n),r)}function x(t,e,n){let s=t.ex+n;return s===0?V(t.m,t.e2):Rt(t.m,t.e2,s*e)}function Yt(t,e){if(t===.5)return{m:Math.sqrt(2/(e*Math.PI))*(-Math.expm1(-2*e)/2),e2:0,ex:1};if(t>0&&e/t<.25)return{m:Kt(t,e),e2:0,ex:0};let n=(4*t*t+10)/(8*e);if(n*=n,n*=n,n/=24,n<D*10&&e>100){let i=4*t*t,c=8*e,l=i-1,f=c,m=1-l/f;return l*=i-9,f*=c*2,m+=l/f,l*=i-25,f*=c*3,m-=l/f,{m:m/Math.sqrt(2*e*Math.PI),e2:0,ex:1}}let{k:s,k1:r,exp2:o}=bt(t,e),a=At(t,e);return{m:1/(e*(s*a+r)),e2:-o,ex:1}}function Nt(t,e){let n=4*t*t,s=8*e,r=(n-1)/s,o=r*(n-9)/(2*s),a=o*(n-25)/(3*s),i=a*(n-49)/(4*s),c=1+r+o+a;if(Math.abs(i)<D*Math.abs(c))return{m:c*Math.sqrt(Math.PI)/Math.sqrt(2*e),e2:0,ex:-1};let{k:l,exp2:f}=bt(t,e);return{m:l,e2:f,ex:-1}}function Ct(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e),o=e<0&&e!==Math.floor(e);if(t===0)return o?d(r)>0?1/0:-1/0:e===0?1:0;if(t===1/0)return s?0:1/0;let a=s?-1:0,i=x(Yt(r,t),t,a);if(!o)return i;let c=Nt(r,t);return i+x({...c,m:2/Math.PI*d(r)*c.m},t,a)}function Qt(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e);return t===0?1/0:t===1/0?0:x(Nt(r,t),t,s?1:0)}var y=Number.EPSILON;function A(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function gt(t,e,n,s,r){let o=s,a=r,i=0;for(let c=1;c<=n;c++){let l=2*(t+c)/e,f=Math.log2(Math.abs(a))+Math.log2(l);if(f>900&&Number.isFinite(f)){let u=Math.ceil(f-800);o=A(o,-u),a=A(a,-u),i+=u}let m=l*a-o;o=a,a=m}return{y:o,y1:a,e2:i}}var K=1e6,g=Math.sqrt(22250738585072014e-324),Ut=Number.MAX_VALUE;function It(t){return Math.expm1(C(t))}function Q(t){return d(.5-Math.abs(t%2))}function dt(t,e){let n=-(e/2)*(e/2),s=1,r=0;for(let o=1;o<K&&(r+=s,s*=n/(o*(o+t)),!(Math.abs(s)<=y*Math.abs(r)));o++);return W(t,e,r+s)}function Vt(t,e){let n=Math.log(e/2),s=0,r=t>=170||709.78/t<Math.abs(n),o;if(r){let u=_(t);if(n=t*n,o=u-Math.log(Math.PI)-n,709.78<o){let M=Math.ceil((o-700)/Math.LN2);o-=M*Math.LN2,s=M}o=-Math.exp(o)}else{let u=q(t);n=Math.pow(e/2,t),Ut*n<u&&(u*=2**-1e3,s=1e3),o=-u/(Math.PI*n)}let a=-(e/2)*(e/2),i=1,c=0;for(let u=1;u<K&&(c+=i,i*=a/(u*(u-t)),!(Math.abs(i)<=y*Math.abs(c)));u++);let l=(c+i)*o,f;if(!r)f=q(-t)*Q(t)*n/Math.PI;else{let u=U(-t);f=Math.exp(u.value+n)*u.sign/Math.PI}i=1;let m=0;for(let u=1;u<K&&(m+=i,i*=a/(u*(u+t)),!(Math.abs(i)<=y*Math.abs(m)));u++);return m+=i,l-=A(f*m,-s),{m:l,e2:s}}function Xt(t,e){let n=1,s=0,r=1,o=8*e,a=1,i=4*t*t,c=1,l=!0;do{c*=(i-a*a)/(r*o),s+=c,r+=1,a+=2;let f=(a*a-i)/(r*o);l=Math.abs(f)<.5,c*=f,n+=c,r+=1,a+=2}while(Math.abs(c)>2*y*n&&l);return l?{p:n,q:s}:void 0}function Bt(t,e){let n=It(t),s=It(-t),r=d(t),o=d(t/2),a=Math.pow(e/2,t),i=Math.log(e/2),c=-i*t,l=Math.abs(c)<y?1:Math.sinh(c)/c,f=Math.abs(t)<y?t*Math.PI*Math.PI/2:2*o*o/t,m=t===0?-.5772156649015329:(n-s)/((1+n)*(1+s)*2*t),u=(2+n+s)/((1+n)*(1+s)*2),M=Math.abs(t)<y?1/Math.PI:t/r,p=(m*Math.cosh(c)-u*i*l)*2*M,h=M/(a*(1+s)),S=M*a/(1+n),k=p+f*S,I=h,F=1,R=F*k,X=F*I,B=t*t,b=-e*e/4;for(let N=1;N<K&&(p=(N*p+h+S)/(N*N-B),h/=N-t,S/=N+t,k=p+f*S,I=h-N*k,F*=b/N,R+=F*k,X+=F*I,!(Math.abs(F*k)<Math.abs(R)*y));N++);return[-R,-2*X/e]}function Ot(t,e){let n=[g,0],s=[g,0],r=[0,0],o=1,a=[e,0];for(let i=1;i<K*100;i++){let c=E(t,i),l=O([2*c[0],2*c[1]],a);n=T(l,O([1,0],n)),r=T(l,r),n[0]===0&&(n=[g,0]),r[0]===0&&(r=[g,0]),r=O([1,0],r);let f=J(n,r);if(s=J(s,f),r[0]<0&&(o=-o),Math.abs(f[0]-1+f[1])<y*y)break}return{fv:-(s[0]+s[1]),sign:o}}function yt(t,e){if(e>30)return Ot(t,e);let n=g,s=g,r=0,o=1;for(let a=1;a<K*100;a++){let i=2*(t+a)/e;n=i-1/n,r=i-r,n===0&&(n=g),r===0&&(r=g),r=1/r;let c=n*r;if(s*=c,r<0&&(o=-o),Math.abs(c-1)<2*y)break}return{fv:-s,sign:o}}function Pt(t,e){let n=-.5/e,s=1,r=n,o=s,a=t*t,i=(.25-a)/e,c=2*e,l=2,f=r*r+1;o=l+i*r/f,r=c+i/f;let m=c,u=l;Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f;let M=r*m-o*u,p=o*m+r*u;f=n,n=f*M-s*p,s=f*p+s*M;for(let h=2;h<K&&(i=h-.5,i*=i,i-=a,l+=2,f=r*r+o*o,r=c+i*r/f,o=l-i*o/f,m=c+i*m,u=l+i*u,Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f,M=r*m-o*u,p=o*m+r*u,f=n,n=f*M-s*p,s=f*p+s*M,!(Math.abs(M-1)+Math.abs(p)<2*y));h++);return{p:n,q:s}}function Zt(t,e){let n=1,s=4*t*t,r=2*e;return r*=r,n+=(s-1)/(2*r),n+=3*(s-1)*(s-9)/(r*r*8),n+=15*(s-1)*(s-9)*(s-25)/(r*r*r*8*6),Math.sqrt(n*2/(Math.PI*e))}function Gt(t,e){let n=4*t*t,s=4*e,r=s*s,o=0;return o+=(n-1)/(2*s),s*=r,o+=(n-1)*(n-25)/(6*s),s*=r,o+=(n-1)*(n*n-114*n+1073)/(5*s),s*=r,o+=(n-1)*(5*n*n*n-1535*n*n+54703*n-375733)/(14*s),o}function Wt(t,e){let n=Zt(t,e),s=Gt(t,e),r=Math.cos(e),o=Math.sin(e),a=Q(t/2+.25),i=d(t/2+.25),c=Math.sin(s),l=Math.cos(s),f=(c*(r*a+o*i)+l*(o*a-r*i))*n;return{j:(l*(r*a+o*i)-c*(o*a-r*i))*n,y:f}}function tt(t,e,n){let s=Math.round(t),r=t-s,o=2/(e*Math.PI);if(!n&&(e<5||t>e*e/4))return{j:dt(t,e),y:{m:NaN,e2:0}};if(e<1&&r!==0&&Math.log(y/2)>t*Math.log(e/2*(e/2)/t))return{j:dt(t,e),y:Vt(t,e)};if(Math.max(t,1)<e*.011048543456039806){let b=Wt(t,e);return{j:b.j,y:{m:b.y,e2:0}}}if(e>8){let b=Xt(t,e);if(b!==void 0){let N=(t/2+.25)%2,P=Math.sin(e),w=Math.cos(e),Y=d(N),rt=Q(N),st=P*rt-Y*w,ot=w*rt+P*Y,it=Math.SQRT2/(Math.sqrt(Math.PI)*Math.sqrt(e));return{j:it*(b.p*ot-b.q*st),y:{m:it*(b.p*st+b.q*ot),e2:0}}}}if(e<=2){let[b,N]=Bt(r,e),P=gt(r,e,s,b,N),{fv:w}=yt(t,e);return{j:A(o/(P.y*w-P.y1),-P.e2),y:{m:P.y,e2:P.e2}}}let{fv:a,sign:i}=yt(t,e);if(e>=t&&t>2){let{p:b,q:N}=Pt(t,e),P=t/e-a,w=(b-P)/N;w===0&&(w=t*y/e);let Y=i*Math.sqrt(o/(N+w*(b-P)));return{j:Y,y:{m:w*Y,e2:0}}}let c=g,l=a*i*c,f=i*c,m=0;for(let b=s;b>0;b--){let N=2*(r+b)/e;Math.abs(f)>2**900&&(l*=2**-900,f*=2**-900,m+=900);let P=N*f-l;P===0&&(P=l*y/2),l=f,f=P}let u=A(i*c/f,-m),M=l/f,{p,q:h}=Pt(r,e),S=r/e-M,k=(p-S)/h;k===0&&(k=r*y/e);let I=Math.sign(f)*Math.sqrt(o/(h+k*(p-S))),F=I*u,R=k*I,X=R*(r/e-p-h/k);if(!n)return{j:F,y:{m:NaN,e2:0}};let B=gt(r,e,s,R,X);return{j:F,y:{m:B.y,e2:B.e2}}}function Ht(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0&&e!==Math.floor(e);if(t===0)return e===0?1:s?d(n)>0?1/0:-1/0:0;if(t===1/0)return 0;if(!s){let o=tt(n,t,!1).j;return e<0&&n%2===1?-o:o}let r=tt(n,t,!0);return Q(n)*r.j-A(d(n)*r.y.m,r.y.e2)}function $t(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0;if(t===0){if(!s)return-1/0;let i=Q(n);return i===0?0:i>0?-1/0:1/0}if(t===1/0)return 0;let r=tt(n,t,!0);if(!s)return A(r.y.m,r.y.e2);let o=Q(n),a=d(n);return(a!==0?a*r.j:0)+(o===0?0:A(o*r.y.m,r.y.e2))}function zt(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!(e>0))return{lower:NaN,upper:NaN,logLower:NaN,logUpper:NaN};let n=_(e),s=q(e),r=l=>{let f=v(e,t,l,!1),m=s*f;if(Number.isFinite(s)&&f>kt&&Number.isFinite(m)&&m>kt)return[m,Math.log(m)];let u=n+v(e,t,l,!0);return u<710&&u>-746&&t>0&&(l?t<e:t>e)?vt(t,e,l):[Math.exp(u),u]},[o,a]=r(!0),[i,c]=r(!1);return{lower:o,upper:i,logLower:a,logUpper:c}}var kt=22250738585072014e-324;function vt(t,e,n){let s=j(at(L([t,0]),e),[-t,0]);n?s=j(s,L([mt(e,t)/e,0])):s=j(s,L([ut(e,t),0]));let r=s[0]+s[1];return[s[0]>-708?Math.exp(s[0])*(1+s[1]):Math.exp(r),r]}function et(t){return Number.isNaN(t)||t<0||t>2?NaN:-ft(t/2)*Math.SQRT1_2}function xt(t){if(Number.isNaN(t)||t<-1||t>1)return NaN;let e=t<0?-1:1,n=Math.abs(t);if(n>=.5)return e*et(1-n);if(n<1e-8)return t*.886226925452758*(1+Math.PI/12*t*t);let s=et(1-n);for(let r=0;r<3;r++){let o=($(s)-n)/(1.1283791670955126*Math.exp(-s*s));if(s-=o,Math.abs(o)<=1e-17*s)break}return e*s}function te(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||e<0)return NaN;let n=e===Math.floor(e);return t===Math.floor(t)&&n&&e>t?0:!Number.isFinite(t)||!Number.isFinite(e)?ie(t,e):n&&e<=1e3?ee(t,e):ne(t,e)}function ee(t,e){let n=[1,0];for(let s=0;s<e;s++){let r=E(t,-s),o=n[0]*r[0];if(!Number.isFinite(o)){let a=Math.sign(o);for(let i=s+1;i<e;i++)t-i<0&&(a=-a);return a*(1/0)}n=Math.abs(n[0])>1e290||Math.abs(r[0])>1e290?[(n[0]+n[1])*(r[0]+r[1]),0]:J(n,r)}return n[0]+n[1]}function ne(t,e){let[n,s]=E(t,-e);if(n+1<=0)return re(t,n,s);if(t>1e280)return e*e<1e-17*t?Math.pow(t,e):1/0;let r;if(n>=15){if(e*Math.log(n+1)>720)return 1/0;let o=E(t,-n),a=T(J(o,L([t,0])),ct(n,[t,0]));a=j(a,[Z(t)-Z(n),0]),r=Math.sqrt(t/n)*Math.exp(a[0])*(1+a[1])}else if(t<30)r=q(t+1)/q(n+1);else{if(_(t+1)-_(n+1)>720)return 1/0;let o=T(nt(t+1),L([q(n+1),0]));r=Math.exp(o[0])*(1+o[1])}return s!==0&&Number.isFinite(r)&&r!==0&&(r*=Math.exp(-s*G(n+1))),r}function re(t,e,n){let s=j(E(e,1),[n,0]),r=d(s[0])+d(s[0]+.5)*Math.PI*s[1];if(r===0)return 0;let o=Math.sign(r),a=j(T(L([Math.abs(r),0]),oe),[-n*G(-e),0]);if(_(t+1)+_(-e)+a[0]>720)return o*(1/0);let i=j(j(nt(t+1),nt(-e)),a);return o*Math.exp(i[0])*(1+i[1])}var se=[.9189385332046728,-38782941580672414e-33],oe=[1.1447298858494002,10265951162707826e-33];function nt(t){if(t<15)return L([q(t),0]);let e=T(J(E(t,-.5),L([t,0])),[t,0]);return j(j(e,se),[Z(t),0])}function ie(t,e){let n=U(t+1),s=U(t-e+1);return n.sign*s.sign*Math.exp(n.value-s.value)}function ae(t){return Number.isNaN(t)||t<-1?NaN:t===-1||t===1/0?-1/0:lt(t)}function fe(t){return Number.isNaN(t)||t===-1/0?NaN:t===1/0||t<=-1&&t===Math.floor(t)?1/0:C(t)}function ce(t){return Number.isNaN(t)||t<0?NaN:t===0?-1/0:t===1/0?0:ht(-t)}function le(t){return Number.isNaN(t)?NaN:t<=-37?Math.exp(t):t<=18?Math.log1p(Math.exp(t)):t<=33.3?t+Math.exp(-t):t}export{Ct as besselI,Ht as besselJ,Qt as besselK,$t as besselY,Dt as beta,wt as choose,G as digamma,$ as erf,qt as erfc,et as erfcinv,xt as erfinv,_t as factorial,q as gamma,zt as gammainc,Ft as lbeta,Lt as lchoose,Et as lfactorial,_ as lgamma,fe as lgamma1p,ce as log1mexp,le as log1pexp,ae as log1pmx,te as perm,jt as psigamma,St as trigamma};
1
+ /*! rStats.js 0.15.3 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{a as wt,b as Lt,c as _t,d as Et}from"./chunks/chunk-NM3Z2UBQ.js";import{c as G,d as St,e as jt}from"./chunks/chunk-FKAKALOZ.js";import{A as v,H as ht,M as Dt,N as Ft,b as $,c as qt,h as ft,k as d,l as q,m as U,n as _,o as C,p as Z,q as ct,u as z,v as lt,w as mt,y as ut}from"./chunks/chunk-3TSWYE5L.js";import{b as E,d as j,f as T,g as J,h as at,i as O,k as L}from"./chunks/chunk-KT66SB7R.js";var Mt=22250738585072014e-324;function W(t,e,n){if(t<10)return Math.pow(e/2,t)/q(t+1)*n;let s=e/2,r=z(t,s,!1);if(r>=Mt&&s<700){let a=r*Math.exp(s)*n;if(Math.abs(a)>=Mt)return a}let o=z(t,s,!0)+s+Math.log(Math.abs(n));return Math.sign(n)*Math.exp(o)}var D=Number.EPSILON,H=1e6;function pt(t){return Math.expm1(C(t))}function Tt(t,e){let n=pt(t),s=pt(-t),r=Math.log(e/2),o=Math.exp(t*r),a=-r*t,i=Math.abs(t)<D?1:d(t)/(t*Math.PI),c=Math.abs(a)<D?1:Math.sinh(a)/a,l=Math.abs(t)<D?-.5772156649015329:.5/t*(n-s)*i,f=(2+n+s)*i/2,m=(n+1)/(2*o),u=(1+s)*o/2,M=(Math.cosh(a)*l+c*-r*f)/i,p=m,h=1,S=h*M,k=h*p;for(let I=1;I<H&&(M=(I*M+m+u)/(I*I-t*t),m/=I-t,u/=I+t,p=m-I*M,h*=e*e/(4*I),S+=h*M,k+=h*p,!(Math.abs(h*M)<Math.abs(S)*D));I++);return[S,2*k/e]}function At(t,e){let n=Math.sqrt(Number.MIN_VALUE*4503599627370496),s=n,r=n,o=0;for(let a=1;a<H;a++){let i=2*(t+a)/e;s=i+1/s,o=i+o,s===0&&(s=n),o===0&&(o=n),o=1/o;let c=s*o;if(r*=c,Math.abs(c-1)<=2*D)break}return r}function Jt(t,e){let n=t*t-.25,s=2*(e+1),r=1/s,o=r,a=r,i=0,c=1,l=-n,f=l,m=1+f*a;for(let p=2;p<H;p++){n-=2*(p-1),s+=2,r=1/(s+n*r),a*=s*r-1,o+=a;let h=(i-(s-2)*c)/n;if(i=c,c=h,l*=-n/p,f+=l*h,m+=f*a,h<D&&(l*=h,i/=h,c/=h),Math.abs(f*a)<Math.abs(m)*D)break}let u=(.5+t+e+(t*t-.25)*o)/e,M=Math.sqrt(Math.PI/(2*e))/m;return[M,M*u]}function V(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function bt(t,e){let n=Math.round(t),s=t-n,r,o;if(s===-.5)r=o=Math.sqrt(Math.PI/(2*e));else if(e<=2){let[i,c]=Tt(s,e),l=Math.exp(e);r=i*l,o=c*l}else[r,o]=Jt(s,e);let a=0;for(let i=1;i<=n;i++){let c=2*(s+i)/e,l=Math.log2(Math.abs(o))+Math.log2(c);if(l>900&&Number.isFinite(l)){let m=Math.ceil(l-800);r=V(r,-m),o=V(o,-m),a+=m}let f=c*o+r;r=o,o=f}return{k:r,k1:o,exp2:a}}function Kt(t,e){let n=e*e/4,s=1,r=0;for(let o=1;o<H&&(r+=s,s*=n/o,s/=o+t,!(Math.abs(s)<=D*Math.abs(r)));o++);return W(t,e,r+s)}function Rt(t,e,n){if(t===0||!Number.isFinite(t))return t;let s=t,r=e,o=n>0?700:-700,a=Math.exp(o);for(;Math.abs(n)>700;){n-=o,s*=a;let i=Math.floor(Math.log2(Math.abs(s)));s=V(s,-i),r+=i}return V(s*Math.exp(n),r)}function x(t,e,n){let s=t.ex+n;return s===0?V(t.m,t.e2):Rt(t.m,t.e2,s*e)}function Yt(t,e){if(t===.5)return{m:Math.sqrt(2/(e*Math.PI))*(-Math.expm1(-2*e)/2),e2:0,ex:1};if(t>0&&e/t<.25)return{m:Kt(t,e),e2:0,ex:0};let n=(4*t*t+10)/(8*e);if(n*=n,n*=n,n/=24,n<D*10&&e>100){let i=4*t*t,c=8*e,l=i-1,f=c,m=1-l/f;return l*=i-9,f*=c*2,m+=l/f,l*=i-25,f*=c*3,m-=l/f,{m:m/Math.sqrt(2*e*Math.PI),e2:0,ex:1}}let{k:s,k1:r,exp2:o}=bt(t,e),a=At(t,e);return{m:1/(e*(s*a+r)),e2:-o,ex:1}}function Nt(t,e){let n=4*t*t,s=8*e,r=(n-1)/s,o=r*(n-9)/(2*s),a=o*(n-25)/(3*s),i=a*(n-49)/(4*s),c=1+r+o+a;if(Math.abs(i)<D*Math.abs(c))return{m:c*Math.sqrt(Math.PI)/Math.sqrt(2*e),e2:0,ex:-1};let{k:l,exp2:f}=bt(t,e);return{m:l,e2:f,ex:-1}}function Ct(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e),o=e<0&&e!==Math.floor(e);if(t===0)return o?d(r)>0?1/0:-1/0:e===0?1:0;if(t===1/0)return s?0:1/0;let a=s?-1:0,i=x(Yt(r,t),t,a);if(!o)return i;let c=Nt(r,t);return i+x({...c,m:2/Math.PI*d(r)*c.m},t,a)}function Qt(t,e,n={}){let s=n.exponScaled??!1;if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let r=Math.abs(e);return t===0?1/0:t===1/0?0:x(Nt(r,t),t,s?1:0)}var y=Number.EPSILON;function A(t,e){if(!Number.isFinite(e))return e>0?t*(1/0):t*0;for(;e>1e3;)t*=2**1e3,e-=1e3;for(;e<-1e3;)t*=2**-1e3,e+=1e3;return t*2**e}function gt(t,e,n,s,r){let o=s,a=r,i=0;for(let c=1;c<=n;c++){let l=2*(t+c)/e,f=Math.log2(Math.abs(a))+Math.log2(l);if(f>900&&Number.isFinite(f)){let u=Math.ceil(f-800);o=A(o,-u),a=A(a,-u),i+=u}let m=l*a-o;o=a,a=m}return{y:o,y1:a,e2:i}}var K=1e6,g=Math.sqrt(22250738585072014e-324),Ut=Number.MAX_VALUE;function It(t){return Math.expm1(C(t))}function Q(t){return d(.5-Math.abs(t%2))}function dt(t,e){let n=-(e/2)*(e/2),s=1,r=0;for(let o=1;o<K&&(r+=s,s*=n/(o*(o+t)),!(Math.abs(s)<=y*Math.abs(r)));o++);return W(t,e,r+s)}function Vt(t,e){let n=Math.log(e/2),s=0,r=t>=170||709.78/t<Math.abs(n),o;if(r){let u=_(t);if(n=t*n,o=u-Math.log(Math.PI)-n,709.78<o){let M=Math.ceil((o-700)/Math.LN2);o-=M*Math.LN2,s=M}o=-Math.exp(o)}else{let u=q(t);n=Math.pow(e/2,t),Ut*n<u&&(u*=2**-1e3,s=1e3),o=-u/(Math.PI*n)}let a=-(e/2)*(e/2),i=1,c=0;for(let u=1;u<K&&(c+=i,i*=a/(u*(u-t)),!(Math.abs(i)<=y*Math.abs(c)));u++);let l=(c+i)*o,f;if(!r)f=q(-t)*Q(t)*n/Math.PI;else{let u=U(-t);f=Math.exp(u.value+n)*u.sign/Math.PI}i=1;let m=0;for(let u=1;u<K&&(m+=i,i*=a/(u*(u+t)),!(Math.abs(i)<=y*Math.abs(m)));u++);return m+=i,l-=A(f*m,-s),{m:l,e2:s}}function Xt(t,e){let n=1,s=0,r=1,o=8*e,a=1,i=4*t*t,c=1,l=!0;do{c*=(i-a*a)/(r*o),s+=c,r+=1,a+=2;let f=(a*a-i)/(r*o);l=Math.abs(f)<.5,c*=f,n+=c,r+=1,a+=2}while(Math.abs(c)>2*y*n&&l);return l?{p:n,q:s}:void 0}function Bt(t,e){let n=It(t),s=It(-t),r=d(t),o=d(t/2),a=Math.pow(e/2,t),i=Math.log(e/2),c=-i*t,l=Math.abs(c)<y?1:Math.sinh(c)/c,f=Math.abs(t)<y?t*Math.PI*Math.PI/2:2*o*o/t,m=t===0?-.5772156649015329:(n-s)/((1+n)*(1+s)*2*t),u=(2+n+s)/((1+n)*(1+s)*2),M=Math.abs(t)<y?1/Math.PI:t/r,p=(m*Math.cosh(c)-u*i*l)*2*M,h=M/(a*(1+s)),S=M*a/(1+n),k=p+f*S,I=h,F=1,R=F*k,X=F*I,B=t*t,b=-e*e/4;for(let N=1;N<K&&(p=(N*p+h+S)/(N*N-B),h/=N-t,S/=N+t,k=p+f*S,I=h-N*k,F*=b/N,R+=F*k,X+=F*I,!(Math.abs(F*k)<Math.abs(R)*y));N++);return[-R,-2*X/e]}function Ot(t,e){let n=[g,0],s=[g,0],r=[0,0],o=1,a=[e,0];for(let i=1;i<K*100;i++){let c=E(t,i),l=O([2*c[0],2*c[1]],a);n=T(l,O([1,0],n)),r=T(l,r),n[0]===0&&(n=[g,0]),r[0]===0&&(r=[g,0]),r=O([1,0],r);let f=J(n,r);if(s=J(s,f),r[0]<0&&(o=-o),Math.abs(f[0]-1+f[1])<y*y)break}return{fv:-(s[0]+s[1]),sign:o}}function yt(t,e){if(e>30)return Ot(t,e);let n=g,s=g,r=0,o=1;for(let a=1;a<K*100;a++){let i=2*(t+a)/e;n=i-1/n,r=i-r,n===0&&(n=g),r===0&&(r=g),r=1/r;let c=n*r;if(s*=c,r<0&&(o=-o),Math.abs(c-1)<2*y)break}return{fv:-s,sign:o}}function Pt(t,e){let n=-.5/e,s=1,r=n,o=s,a=t*t,i=(.25-a)/e,c=2*e,l=2,f=r*r+1;o=l+i*r/f,r=c+i/f;let m=c,u=l;Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f;let M=r*m-o*u,p=o*m+r*u;f=n,n=f*M-s*p,s=f*p+s*M;for(let h=2;h<K&&(i=h-.5,i*=i,i-=a,l+=2,f=r*r+o*o,r=c+i*r/f,o=l-i*o/f,m=c+i*m,u=l+i*u,Math.abs(r)+Math.abs(o)<g&&(r=g),Math.abs(m)+Math.abs(u)<g&&(m=g),f=m*m+u*u,m=m/f,u=-u/f,M=r*m-o*u,p=o*m+r*u,f=n,n=f*M-s*p,s=f*p+s*M,!(Math.abs(M-1)+Math.abs(p)<2*y));h++);return{p:n,q:s}}function Zt(t,e){let n=1,s=4*t*t,r=2*e;return r*=r,n+=(s-1)/(2*r),n+=3*(s-1)*(s-9)/(r*r*8),n+=15*(s-1)*(s-9)*(s-25)/(r*r*r*8*6),Math.sqrt(n*2/(Math.PI*e))}function Gt(t,e){let n=4*t*t,s=4*e,r=s*s,o=0;return o+=(n-1)/(2*s),s*=r,o+=(n-1)*(n-25)/(6*s),s*=r,o+=(n-1)*(n*n-114*n+1073)/(5*s),s*=r,o+=(n-1)*(5*n*n*n-1535*n*n+54703*n-375733)/(14*s),o}function Wt(t,e){let n=Zt(t,e),s=Gt(t,e),r=Math.cos(e),o=Math.sin(e),a=Q(t/2+.25),i=d(t/2+.25),c=Math.sin(s),l=Math.cos(s),f=(c*(r*a+o*i)+l*(o*a-r*i))*n;return{j:(l*(r*a+o*i)-c*(o*a-r*i))*n,y:f}}function tt(t,e,n){let s=Math.round(t),r=t-s,o=2/(e*Math.PI);if(!n&&(e<5||t>e*e/4))return{j:dt(t,e),y:{m:NaN,e2:0}};if(e<1&&r!==0&&Math.log(y/2)>t*Math.log(e/2*(e/2)/t))return{j:dt(t,e),y:Vt(t,e)};if(Math.max(t,1)<e*.011048543456039806){let b=Wt(t,e);return{j:b.j,y:{m:b.y,e2:0}}}if(e>8){let b=Xt(t,e);if(b!==void 0){let N=(t/2+.25)%2,P=Math.sin(e),w=Math.cos(e),Y=d(N),rt=Q(N),st=P*rt-Y*w,ot=w*rt+P*Y,it=Math.SQRT2/(Math.sqrt(Math.PI)*Math.sqrt(e));return{j:it*(b.p*ot-b.q*st),y:{m:it*(b.p*st+b.q*ot),e2:0}}}}if(e<=2){let[b,N]=Bt(r,e),P=gt(r,e,s,b,N),{fv:w}=yt(t,e);return{j:A(o/(P.y*w-P.y1),-P.e2),y:{m:P.y,e2:P.e2}}}let{fv:a,sign:i}=yt(t,e);if(e>=t&&t>2){let{p:b,q:N}=Pt(t,e),P=t/e-a,w=(b-P)/N;w===0&&(w=t*y/e);let Y=i*Math.sqrt(o/(N+w*(b-P)));return{j:Y,y:{m:w*Y,e2:0}}}let c=g,l=a*i*c,f=i*c,m=0;for(let b=s;b>0;b--){let N=2*(r+b)/e;Math.abs(f)>2**900&&(l*=2**-900,f*=2**-900,m+=900);let P=N*f-l;P===0&&(P=l*y/2),l=f,f=P}let u=A(i*c/f,-m),M=l/f,{p,q:h}=Pt(r,e),S=r/e-M,k=(p-S)/h;k===0&&(k=r*y/e);let I=Math.sign(f)*Math.sqrt(o/(h+k*(p-S))),F=I*u,R=k*I,X=R*(r/e-p-h/k);if(!n)return{j:F,y:{m:NaN,e2:0}};let B=gt(r,e,s,R,X);return{j:F,y:{m:B.y,e2:B.e2}}}function Ht(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0&&e!==Math.floor(e);if(t===0)return e===0?1:s?d(n)>0?1/0:-1/0:0;if(t===1/0)return 0;if(!s){let o=tt(n,t,!1).j;return e<0&&n%2===1?-o:o}let r=tt(n,t,!0);return Q(n)*r.j-A(d(n)*r.y.m,r.y.e2)}function $t(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!Number.isFinite(e))return NaN;let n=Math.abs(e),s=e<0;if(t===0){if(!s)return-1/0;let i=Q(n);return i===0?0:i>0?-1/0:1/0}if(t===1/0)return 0;let r=tt(n,t,!0);if(!s)return A(r.y.m,r.y.e2);let o=Q(n),a=d(n);return(a!==0?a*r.j:0)+(o===0?0:A(o*r.y.m,r.y.e2))}function zt(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||!(e>0))return{lower:NaN,upper:NaN,logLower:NaN,logUpper:NaN};let n=_(e),s=q(e),r=l=>{let f=v(e,t,l,!1),m=s*f;if(Number.isFinite(s)&&f>kt&&Number.isFinite(m)&&m>kt)return[m,Math.log(m)];let u=n+v(e,t,l,!0);return u<710&&u>-746&&t>0&&(l?t<e:t>e)?vt(t,e,l):[Math.exp(u),u]},[o,a]=r(!0),[i,c]=r(!1);return{lower:o,upper:i,logLower:a,logUpper:c}}var kt=22250738585072014e-324;function vt(t,e,n){let s=j(at(L([t,0]),e),[-t,0]);n?s=j(s,L([mt(e,t)/e,0])):s=j(s,L([ut(e,t),0]));let r=s[0]+s[1];return[s[0]>-708?Math.exp(s[0])*(1+s[1]):Math.exp(r),r]}function et(t){return Number.isNaN(t)||t<0||t>2?NaN:-ft(t/2)*Math.SQRT1_2}function xt(t){if(Number.isNaN(t)||t<-1||t>1)return NaN;let e=t<0?-1:1,n=Math.abs(t);if(n>=.5)return e*et(1-n);if(n<1e-8)return t*.886226925452758*(1+Math.PI/12*t*t);let s=et(1-n);for(let r=0;r<3;r++){let o=($(s)-n)/(1.1283791670955126*Math.exp(-s*s));if(s-=o,Math.abs(o)<=1e-17*s)break}return e*s}function te(t,e){if(Number.isNaN(t)||Number.isNaN(e)||t<0||e<0)return NaN;let n=e===Math.floor(e);return t===Math.floor(t)&&n&&e>t?0:!Number.isFinite(t)||!Number.isFinite(e)?ie(t,e):n&&e<=1e3?ee(t,e):ne(t,e)}function ee(t,e){let n=[1,0];for(let s=0;s<e;s++){let r=E(t,-s),o=n[0]*r[0];if(!Number.isFinite(o)){let a=Math.sign(o);for(let i=s+1;i<e;i++)t-i<0&&(a=-a);return a*(1/0)}n=Math.abs(n[0])>1e290||Math.abs(r[0])>1e290?[(n[0]+n[1])*(r[0]+r[1]),0]:J(n,r)}return n[0]+n[1]}function ne(t,e){let[n,s]=E(t,-e);if(n+1<=0)return re(t,n,s);if(t>1e280)return e*e<1e-17*t?Math.pow(t,e):1/0;let r;if(n>=15){if(e*Math.log(n+1)>720)return 1/0;let o=E(t,-n),a=T(J(o,L([t,0])),ct(n,[t,0]));a=j(a,[Z(t)-Z(n),0]),r=Math.sqrt(t/n)*Math.exp(a[0])*(1+a[1])}else if(t<30)r=q(t+1)/q(n+1);else{if(_(t+1)-_(n+1)>720)return 1/0;let o=T(nt(t+1),L([q(n+1),0]));r=Math.exp(o[0])*(1+o[1])}return s!==0&&Number.isFinite(r)&&r!==0&&(r*=Math.exp(-s*G(n+1))),r}function re(t,e,n){let s=j(E(e,1),[n,0]),r=d(s[0])+d(s[0]+.5)*Math.PI*s[1];if(r===0)return 0;let o=Math.sign(r),a=j(T(L([Math.abs(r),0]),oe),[-n*G(-e),0]);if(_(t+1)+_(-e)+a[0]>720)return o*(1/0);let i=j(j(nt(t+1),nt(-e)),a);return o*Math.exp(i[0])*(1+i[1])}var se=[.9189385332046728,-38782941580672414e-33],oe=[1.1447298858494002,10265951162707826e-33];function nt(t){if(t<15)return L([q(t),0]);let e=T(J(E(t,-.5),L([t,0])),[t,0]);return j(j(e,se),[Z(t),0])}function ie(t,e){let n=U(t+1),s=U(t-e+1);return n.sign*s.sign*Math.exp(n.value-s.value)}function ae(t){return Number.isNaN(t)||t<-1?NaN:t===-1||t===1/0?-1/0:lt(t)}function fe(t){return Number.isNaN(t)||t===-1/0?NaN:t===1/0||t<=-1&&t===Math.floor(t)?1/0:C(t)}function ce(t){return Number.isNaN(t)||t<0?NaN:t===0?-1/0:t===1/0?0:ht(-t)}function le(t){return Number.isNaN(t)?NaN:t<=-37?Math.exp(t):t<=18?Math.log1p(Math.exp(t)):t<=33.3?t+Math.exp(-t):t}export{Ct as besselI,Ht as besselJ,Qt as besselK,$t as besselY,Dt as beta,wt as choose,G as digamma,$ as erf,qt as erfc,et as erfcinv,xt as erfinv,_t as factorial,q as gamma,zt as gammainc,Ft as lbeta,Lt as lchoose,Et as lfactorial,_ as lgamma,fe as lgamma1p,ce as log1mexp,le as log1pexp,ae as log1pmx,te as perm,jt as psigamma,St as trigamma};