@syncfusion/ej2-calculate 35.1.37

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 (173) hide show
  1. package/.eslintrc.json +263 -0
  2. package/README.md +132 -0
  3. package/base.d.ts +4 -0
  4. package/base.js +4 -0
  5. package/common.d.ts +4 -0
  6. package/common.js +4 -0
  7. package/dist/ej2-calculate.umd.min.js +11 -0
  8. package/dist/ej2-calculate.umd.min.js.map +1 -0
  9. package/dist/es6/ej2-calculate.es2015.js +24801 -0
  10. package/dist/es6/ej2-calculate.es2015.js.map +1 -0
  11. package/dist/es6/ej2-calculate.es5.js +27229 -0
  12. package/dist/es6/ej2-calculate.es5.js.map +1 -0
  13. package/dist/global/ej2-calculate.min.js +11 -0
  14. package/dist/global/ej2-calculate.min.js.map +1 -0
  15. package/dist/global/index.d.ts +14 -0
  16. package/formulas.d.ts +4 -0
  17. package/formulas.js +4 -0
  18. package/index.d.ts +4 -0
  19. package/index.js +4 -0
  20. package/license +10 -0
  21. package/package.json +30 -0
  22. package/src/base/calculate-model.d.ts +4 -0
  23. package/src/base/calculate-model.js +0 -0
  24. package/src/base/calculate.d.ts +1105 -0
  25. package/src/base/calculate.js +4720 -0
  26. package/src/base/index.d.ts +8 -0
  27. package/src/base/index.js +7 -0
  28. package/src/base/parser.d.ts +208 -0
  29. package/src/base/parser.js +1512 -0
  30. package/src/common/address.d.ts +59 -0
  31. package/src/common/address.js +96 -0
  32. package/src/common/cell-ref.d.ts +32 -0
  33. package/src/common/cell-ref.js +112 -0
  34. package/src/common/common.d.ts +44 -0
  35. package/src/common/common.js +134 -0
  36. package/src/common/enum.d.ts +94 -0
  37. package/src/common/enum.js +97 -0
  38. package/src/common/index.d.ts +9 -0
  39. package/src/common/index.js +8 -0
  40. package/src/common/interface.d.ts +122 -0
  41. package/src/common/interface.js +0 -0
  42. package/src/common/l10n.d.ts +24 -0
  43. package/src/common/l10n.js +54 -0
  44. package/src/common/number-date.d.ts +26 -0
  45. package/src/common/number-date.js +38 -0
  46. package/src/common/sheet-info.d.ts +10 -0
  47. package/src/common/sheet-info.js +17 -0
  48. package/src/common/sort.d.ts +17 -0
  49. package/src/common/sort.js +44 -0
  50. package/src/formulas/array.d.ts +47 -0
  51. package/src/formulas/array.js +718 -0
  52. package/src/formulas/basic.d.ts +47 -0
  53. package/src/formulas/basic.js +181 -0
  54. package/src/formulas/complex-numbers.d.ts +207 -0
  55. package/src/formulas/complex-numbers.js +549 -0
  56. package/src/formulas/database.d.ts +152 -0
  57. package/src/formulas/database.js +579 -0
  58. package/src/formulas/date-time-extra.d.ts +97 -0
  59. package/src/formulas/date-time-extra.js +415 -0
  60. package/src/formulas/date-time-intl.d.ts +57 -0
  61. package/src/formulas/date-time-intl.js +309 -0
  62. package/src/formulas/date-time.d.ts +164 -0
  63. package/src/formulas/date-time.js +1021 -0
  64. package/src/formulas/engineering-base.d.ts +150 -0
  65. package/src/formulas/engineering-base.js +404 -0
  66. package/src/formulas/engineering-bessel.d.ts +65 -0
  67. package/src/formulas/engineering-bessel.js +167 -0
  68. package/src/formulas/engineering-convert.d.ts +35 -0
  69. package/src/formulas/engineering-convert.js +120 -0
  70. package/src/formulas/engineering-misc.d.ts +64 -0
  71. package/src/formulas/engineering-misc.js +168 -0
  72. package/src/formulas/financial-amortization-ecma.d.ts +87 -0
  73. package/src/formulas/financial-amortization-ecma.js +288 -0
  74. package/src/formulas/financial-annuity.d.ts +104 -0
  75. package/src/formulas/financial-annuity.js +419 -0
  76. package/src/formulas/financial-bond-helpers.d.ts +106 -0
  77. package/src/formulas/financial-bond-helpers.js +190 -0
  78. package/src/formulas/financial-cashflow.d.ts +47 -0
  79. package/src/formulas/financial-cashflow.js +203 -0
  80. package/src/formulas/financial-coupons.d.ts +227 -0
  81. package/src/formulas/financial-coupons.js +810 -0
  82. package/src/formulas/financial-depreciation.d.ts +64 -0
  83. package/src/formulas/financial-depreciation.js +247 -0
  84. package/src/formulas/financial-rates.d.ts +54 -0
  85. package/src/formulas/financial-rates.js +140 -0
  86. package/src/formulas/financial-securities.d.ts +126 -0
  87. package/src/formulas/financial-securities.js +488 -0
  88. package/src/formulas/formula-math-helpers.d.ts +212 -0
  89. package/src/formulas/formula-math-helpers.js +599 -0
  90. package/src/formulas/formula-module-base.d.ts +54 -0
  91. package/src/formulas/formula-module-base.js +125 -0
  92. package/src/formulas/formula-owner.d.ts +17 -0
  93. package/src/formulas/formula-owner.js +0 -0
  94. package/src/formulas/index.d.ts +68 -0
  95. package/src/formulas/index.js +67 -0
  96. package/src/formulas/information-advanced.d.ts +44 -0
  97. package/src/formulas/information-advanced.js +157 -0
  98. package/src/formulas/information-ecma.d.ts +33 -0
  99. package/src/formulas/information-ecma.js +88 -0
  100. package/src/formulas/information-extra.d.ts +146 -0
  101. package/src/formulas/information-extra.js +351 -0
  102. package/src/formulas/information.d.ts +34 -0
  103. package/src/formulas/information.js +78 -0
  104. package/src/formulas/logical-extra.d.ts +75 -0
  105. package/src/formulas/logical-extra.js +217 -0
  106. package/src/formulas/logical.d.ts +83 -0
  107. package/src/formulas/logical.js +296 -0
  108. package/src/formulas/lookup-array.d.ts +98 -0
  109. package/src/formulas/lookup-array.js +364 -0
  110. package/src/formulas/lookup-ref-extra.d.ts +64 -0
  111. package/src/formulas/lookup-ref-extra.js +180 -0
  112. package/src/formulas/lookup-ref.d.ts +84 -0
  113. package/src/formulas/lookup-ref.js +263 -0
  114. package/src/formulas/lookup.d.ts +114 -0
  115. package/src/formulas/lookup.js +881 -0
  116. package/src/formulas/math-aggregate.d.ts +74 -0
  117. package/src/formulas/math-aggregate.js +376 -0
  118. package/src/formulas/math-ceiling-ecma.d.ts +42 -0
  119. package/src/formulas/math-ceiling-ecma.js +123 -0
  120. package/src/formulas/math-combinatorics.d.ts +75 -0
  121. package/src/formulas/math-combinatorics.js +290 -0
  122. package/src/formulas/math-misc.d.ts +164 -0
  123. package/src/formulas/math-misc.js +889 -0
  124. package/src/formulas/math-number.d.ts +76 -0
  125. package/src/formulas/math-number.js +261 -0
  126. package/src/formulas/math-rounding.d.ts +115 -0
  127. package/src/formulas/math-rounding.js +728 -0
  128. package/src/formulas/math-trig-hyperbolic.d.ts +55 -0
  129. package/src/formulas/math-trig-hyperbolic.js +113 -0
  130. package/src/formulas/math-trig.d.ts +165 -0
  131. package/src/formulas/math-trig.js +334 -0
  132. package/src/formulas/matrix-base.d.ts +13 -0
  133. package/src/formulas/matrix-base.js +169 -0
  134. package/src/formulas/matrix.d.ts +64 -0
  135. package/src/formulas/matrix.js +161 -0
  136. package/src/formulas/regression-ecma.d.ts +66 -0
  137. package/src/formulas/regression-ecma.js +234 -0
  138. package/src/formulas/statistical-advanced.d.ts +125 -0
  139. package/src/formulas/statistical-advanced.js +756 -0
  140. package/src/formulas/statistical-correlation.d.ts +75 -0
  141. package/src/formulas/statistical-correlation.js +198 -0
  142. package/src/formulas/statistical-dispersion.d.ts +108 -0
  143. package/src/formulas/statistical-dispersion.js +337 -0
  144. package/src/formulas/statistical-distribution-extended.d.ts +176 -0
  145. package/src/formulas/statistical-distribution-extended.js +668 -0
  146. package/src/formulas/statistical-distribution.d.ts +104 -0
  147. package/src/formulas/statistical-distribution.js +368 -0
  148. package/src/formulas/statistical-ecma.d.ts +95 -0
  149. package/src/formulas/statistical-ecma.js +392 -0
  150. package/src/formulas/statistical-extended.d.ts +136 -0
  151. package/src/formulas/statistical-extended.js +340 -0
  152. package/src/formulas/statistical-ifs.d.ts +46 -0
  153. package/src/formulas/statistical-ifs.js +180 -0
  154. package/src/formulas/statistical-moments.d.ts +84 -0
  155. package/src/formulas/statistical-moments.js +269 -0
  156. package/src/formulas/statistical-percentile.d.ts +56 -0
  157. package/src/formulas/statistical-percentile.js +195 -0
  158. package/src/formulas/statistical-sample-base.d.ts +14 -0
  159. package/src/formulas/statistical-sample-base.js +124 -0
  160. package/src/formulas/statistical.d.ts +135 -0
  161. package/src/formulas/statistical.js +542 -0
  162. package/src/formulas/text-advanced.d.ts +64 -0
  163. package/src/formulas/text-advanced.js +222 -0
  164. package/src/formulas/text-ecma.d.ts +54 -0
  165. package/src/formulas/text-ecma.js +106 -0
  166. package/src/formulas/text-extra.d.ts +216 -0
  167. package/src/formulas/text-extra.js +657 -0
  168. package/src/formulas/text.d.ts +125 -0
  169. package/src/formulas/text.js +628 -0
  170. package/src/global.js +1 -0
  171. package/src/index.d.ts +14 -0
  172. package/src/index.js +14 -0
  173. package/tslint.json +111 -0
@@ -0,0 +1,668 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ import { FormulasErrorsStrings, CommonErrors } from '../common/index';
15
+ import { isNullOrUndefined } from '@syncfusion/ej2-base';
16
+ import { StatisticalSampleBase } from './statistical-sample-base';
17
+ import { binomialCoeff, gamma, normCDF, chiSquareCDF, chiSquareInv, fCDF, fInv, logNormCDF, logNormInv, lowerRegularizedGamma } from './formula-math-helpers';
18
+ /**
19
+ * Extended distribution library covering additional continuous and discrete probability models.
20
+ *
21
+ * Registers 15 functions including CRITBINOM, NEGBINOMDIST, HYPGEOMDIST, WEIBULL, LOGNORMDIST, and others.
22
+ *
23
+ * @hidden
24
+ */
25
+ var StatisticalDistributionExtendedFormulas = /** @class */ (function (_super) {
26
+ __extends(StatisticalDistributionExtendedFormulas, _super);
27
+ /**
28
+ * @hidden
29
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
30
+ */
31
+ function StatisticalDistributionExtendedFormulas(owner) {
32
+ var _this = _super.call(this, owner) || this;
33
+ /** Formula definitions registered with {@link BasicFormulas}. */
34
+ _this.formulas = [
35
+ { formulaName: 'CRITBINOM', category: 'Statistical', description: 'Returns the smallest value for which the cumulative binomial distribution is less than or equal to a criterion value.' },
36
+ { formulaName: 'NEGBINOMDIST', category: 'Statistical', description: 'Returns the negative binomial distribution.' },
37
+ { formulaName: 'HYPGEOMDIST', category: 'Statistical', description: 'Returns the hypergeometric distribution.' },
38
+ { formulaName: 'WEIBULL', category: 'Statistical', description: 'Returns the Weibull distribution.' },
39
+ { formulaName: 'LOGNORMDIST', category: 'Statistical', description: 'Returns the cumulative log-normal distribution.' },
40
+ { formulaName: 'LOGINV', category: 'Statistical', description: 'Returns the inverse of the log-normal cumulative distribution.' },
41
+ { formulaName: 'GAMMADIST', category: 'Statistical', description: 'Returns the gamma distribution.' },
42
+ { formulaName: 'GAMMAINV', category: 'Statistical', description: 'Returns the inverse of the gamma cumulative distribution.' },
43
+ { formulaName: 'CHIDIST', category: 'Statistical', description: 'Returns the one-tailed probability of the chi-squared distribution.' },
44
+ { formulaName: 'CHIINV', category: 'Statistical', description: 'Returns the inverse of the one-tailed probability of the chi-squared distribution.' },
45
+ { formulaName: 'CHITEST', category: 'Statistical', description: 'Returns the test for independence.' },
46
+ { formulaName: 'FDIST', category: 'Statistical', description: 'Returns the F probability distribution.' },
47
+ { formulaName: 'FINV', category: 'Statistical', description: 'Returns the inverse of the F probability distribution.' },
48
+ { formulaName: 'ZTEST', category: 'Statistical', description: 'Returns the one-tailed probability-value of a z-test.' },
49
+ { formulaName: 'PROB', category: 'Statistical', description: 'Returns the probability that values in a range are between two limits.' }
50
+ ];
51
+ return _this;
52
+ }
53
+ StatisticalDistributionExtendedFormulas.prototype.parseCumulative = function (args, index) {
54
+ if (args.length <= index) {
55
+ return true;
56
+ }
57
+ var cum = this.resolveNumberArg(args[index]);
58
+ if (typeof cum === 'string') {
59
+ return cum;
60
+ }
61
+ return cum !== 0;
62
+ };
63
+ /**
64
+ * Returns the smallest value for which the cumulative binomial distribution is less than or equal to a criterion value.
65
+ *
66
+ * Excel: `CRITBINOM(...)`.
67
+ *
68
+ * @hidden
69
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
70
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * engine.computeFormula('=CRITBINOM(1)');
75
+ * ```
76
+ */
77
+ StatisticalDistributionExtendedFormulas.prototype.ComputeCRITBINOM = function () {
78
+ var args = [];
79
+ for (var _i = 0; _i < arguments.length; _i++) {
80
+ args[_i] = arguments[_i];
81
+ }
82
+ var errCollection = this.parent.getErrorStrings();
83
+ if (isNullOrUndefined(args) || args.length !== 3) {
84
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
85
+ }
86
+ var trials = this.resolveNumberArg(args[0]);
87
+ var prob = this.resolveNumberArg(args[1]);
88
+ var alpha = this.resolveNumberArg(args[2]);
89
+ if (typeof trials === 'string') {
90
+ return trials;
91
+ }
92
+ if (typeof prob === 'string') {
93
+ return prob;
94
+ }
95
+ if (typeof alpha === 'string') {
96
+ return alpha;
97
+ }
98
+ var n = Math.floor(trials);
99
+ var p = prob;
100
+ if (n < 0 || p < 0 || p > 1 || alpha < 0 || alpha > 1) {
101
+ return errCollection[CommonErrors.Num];
102
+ }
103
+ var cum = 0;
104
+ for (var k = 0; k <= n; k++) {
105
+ cum += binomialCoeff(n, k) * Math.pow(p, k) * Math.pow(1 - p, n - k);
106
+ if (cum >= alpha) {
107
+ return k.toString();
108
+ }
109
+ }
110
+ return n.toString();
111
+ };
112
+ /**
113
+ * Returns the negative binomial distribution.
114
+ *
115
+ * Excel: `NEGBINOMDIST(...)`.
116
+ *
117
+ * @hidden
118
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
119
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
120
+ */
121
+ StatisticalDistributionExtendedFormulas.prototype.ComputeNEGBINOMDIST = function () {
122
+ var args = [];
123
+ for (var _i = 0; _i < arguments.length; _i++) {
124
+ args[_i] = arguments[_i];
125
+ }
126
+ var errCollection = this.parent.getErrorStrings();
127
+ if (isNullOrUndefined(args) || args.length !== 3) {
128
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
129
+ }
130
+ var failures = this.resolveNumberArg(args[0]);
131
+ var successes = this.resolveNumberArg(args[1]);
132
+ var prob = this.resolveNumberArg(args[2]);
133
+ if (typeof failures === 'string') {
134
+ return failures;
135
+ }
136
+ if (typeof successes === 'string') {
137
+ return successes;
138
+ }
139
+ if (typeof prob === 'string') {
140
+ return prob;
141
+ }
142
+ var f = Math.floor(failures);
143
+ var s = Math.floor(successes);
144
+ if (f < 0 || s < 1 || prob <= 0 || prob > 1) {
145
+ return errCollection[CommonErrors.Num];
146
+ }
147
+ var result = binomialCoeff(f + s - 1, s - 1) * Math.pow(prob, s) * Math.pow(1 - prob, f);
148
+ return result.toString();
149
+ };
150
+ /**
151
+ * Returns the hypergeometric distribution.
152
+ *
153
+ * Excel: `HYPGEOMDIST(...)`.
154
+ *
155
+ * @hidden
156
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
157
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
158
+ */
159
+ StatisticalDistributionExtendedFormulas.prototype.ComputeHYPGEOMDIST = function () {
160
+ var args = [];
161
+ for (var _i = 0; _i < arguments.length; _i++) {
162
+ args[_i] = arguments[_i];
163
+ }
164
+ var errCollection = this.parent.getErrorStrings();
165
+ if (isNullOrUndefined(args) || args.length < 4 || args.length > 5) {
166
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
167
+ }
168
+ var sampleS = this.resolveNumberArg(args[0]);
169
+ var numSample = this.resolveNumberArg(args[1]);
170
+ var popS = this.resolveNumberArg(args[2]);
171
+ var numPop = this.resolveNumberArg(args[3]);
172
+ if (typeof sampleS === 'string') {
173
+ return sampleS;
174
+ }
175
+ if (typeof numSample === 'string') {
176
+ return numSample;
177
+ }
178
+ if (typeof popS === 'string') {
179
+ return popS;
180
+ }
181
+ if (typeof numPop === 'string') {
182
+ return numPop;
183
+ }
184
+ var x = Math.floor(sampleS);
185
+ var n = Math.floor(numSample);
186
+ var M = Math.floor(popS);
187
+ var N = Math.floor(numPop);
188
+ if (x < 0 || x > n || n > N || M > N) {
189
+ return errCollection[CommonErrors.Num];
190
+ }
191
+ var cumulative = this.parseCumulative(args, 4);
192
+ if (typeof cumulative === 'string') {
193
+ return cumulative;
194
+ }
195
+ var pmf = (binomialCoeff(M, x) * binomialCoeff(N - M, n - x)) / binomialCoeff(N, n);
196
+ if (!cumulative) {
197
+ return pmf.toString();
198
+ }
199
+ var sum = 0;
200
+ for (var i = 0; i <= x; i++) {
201
+ sum += (binomialCoeff(M, i) * binomialCoeff(N - M, n - i)) / binomialCoeff(N, n);
202
+ }
203
+ return sum.toString();
204
+ };
205
+ /**
206
+ * Returns the Weibull distribution.
207
+ *
208
+ * Excel: `WEIBULL(...)`.
209
+ *
210
+ * @hidden
211
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
212
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
213
+ */
214
+ StatisticalDistributionExtendedFormulas.prototype.ComputeWEIBULL = function () {
215
+ var args = [];
216
+ for (var _i = 0; _i < arguments.length; _i++) {
217
+ args[_i] = arguments[_i];
218
+ }
219
+ var errCollection = this.parent.getErrorStrings();
220
+ if (isNullOrUndefined(args) || args.length < 3 || args.length > 4) {
221
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
222
+ }
223
+ var x = this.resolveNumberArg(args[0]);
224
+ var alpha = this.resolveNumberArg(args[1]);
225
+ var beta = this.resolveNumberArg(args[2]);
226
+ if (typeof x === 'string') {
227
+ return x;
228
+ }
229
+ if (typeof alpha === 'string') {
230
+ return alpha;
231
+ }
232
+ if (typeof beta === 'string') {
233
+ return beta;
234
+ }
235
+ if (x < 0 || alpha <= 0 || beta <= 0) {
236
+ return errCollection[CommonErrors.Num];
237
+ }
238
+ var cumulative = this.parseCumulative(args, 3);
239
+ if (typeof cumulative === 'string') {
240
+ return cumulative;
241
+ }
242
+ if (cumulative) {
243
+ return (1 - Math.exp(-Math.pow(x / beta, alpha))).toString();
244
+ }
245
+ return ((alpha / Math.pow(beta, alpha)) * Math.pow(x, alpha - 1) * Math.exp(-Math.pow(x / beta, alpha))).toString();
246
+ };
247
+ /**
248
+ * Returns the cumulative log-normal distribution.
249
+ *
250
+ * Excel: `LOGNORMDIST(...)`.
251
+ *
252
+ * @hidden
253
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
254
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
255
+ */
256
+ StatisticalDistributionExtendedFormulas.prototype.ComputeLOGNORMDIST = function () {
257
+ var args = [];
258
+ for (var _i = 0; _i < arguments.length; _i++) {
259
+ args[_i] = arguments[_i];
260
+ }
261
+ if (isNullOrUndefined(args) || args.length !== 3) {
262
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
263
+ }
264
+ var x = this.resolveNumberArg(args[0]);
265
+ var mean = this.resolveNumberArg(args[1]);
266
+ var std = this.resolveNumberArg(args[2]);
267
+ if (typeof x === 'string') {
268
+ return x;
269
+ }
270
+ if (typeof mean === 'string') {
271
+ return mean;
272
+ }
273
+ if (typeof std === 'string') {
274
+ return std;
275
+ }
276
+ var result = logNormCDF(x, mean, std);
277
+ if (isNaN(result)) {
278
+ return this.parent.getErrorStrings()[CommonErrors.Num];
279
+ }
280
+ return result.toString();
281
+ };
282
+ /**
283
+ * Returns the inverse of the log-normal cumulative distribution.
284
+ *
285
+ * Excel: `LOGINV(...)`.
286
+ *
287
+ * @hidden
288
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
289
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
290
+ */
291
+ StatisticalDistributionExtendedFormulas.prototype.ComputeLOGINV = function () {
292
+ var args = [];
293
+ for (var _i = 0; _i < arguments.length; _i++) {
294
+ args[_i] = arguments[_i];
295
+ }
296
+ if (isNullOrUndefined(args) || args.length !== 3) {
297
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
298
+ }
299
+ var p = this.resolveNumberArg(args[0]);
300
+ var mean = this.resolveNumberArg(args[1]);
301
+ var std = this.resolveNumberArg(args[2]);
302
+ if (typeof p === 'string') {
303
+ return p;
304
+ }
305
+ if (typeof mean === 'string') {
306
+ return mean;
307
+ }
308
+ if (typeof std === 'string') {
309
+ return std;
310
+ }
311
+ var result = logNormInv(p, mean, std);
312
+ if (isNaN(result)) {
313
+ return this.parent.getErrorStrings()[CommonErrors.Num];
314
+ }
315
+ return result.toString();
316
+ };
317
+ /**
318
+ * Returns the gamma distribution.
319
+ *
320
+ * Excel: `GAMMADIST(...)`.
321
+ *
322
+ * @hidden
323
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
324
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
325
+ */
326
+ StatisticalDistributionExtendedFormulas.prototype.ComputeGAMMADIST = function () {
327
+ var args = [];
328
+ for (var _i = 0; _i < arguments.length; _i++) {
329
+ args[_i] = arguments[_i];
330
+ }
331
+ var errCollection = this.parent.getErrorStrings();
332
+ if (isNullOrUndefined(args) || args.length < 3 || args.length > 4) {
333
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
334
+ }
335
+ var x = this.resolveNumberArg(args[0]);
336
+ var alpha = this.resolveNumberArg(args[1]);
337
+ var beta = this.resolveNumberArg(args[2]);
338
+ if (typeof x === 'string') {
339
+ return x;
340
+ }
341
+ if (typeof alpha === 'string') {
342
+ return alpha;
343
+ }
344
+ if (typeof beta === 'string') {
345
+ return beta;
346
+ }
347
+ if (x < 0 || alpha <= 0 || beta <= 0) {
348
+ return errCollection[CommonErrors.Num];
349
+ }
350
+ var cumulative = this.parseCumulative(args, 3);
351
+ if (typeof cumulative === 'string') {
352
+ return cumulative;
353
+ }
354
+ var scaled = x / beta;
355
+ if (cumulative) {
356
+ return lowerRegularizedGamma(alpha, scaled).toString();
357
+ }
358
+ return (Math.pow(scaled, alpha - 1) * Math.exp(-scaled) / (beta * gamma(alpha))).toString();
359
+ };
360
+ /**
361
+ * Returns the inverse of the gamma cumulative distribution.
362
+ *
363
+ * Excel: `GAMMAINV(...)`.
364
+ *
365
+ * @hidden
366
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
367
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
368
+ */
369
+ StatisticalDistributionExtendedFormulas.prototype.ComputeGAMMAINV = function () {
370
+ var args = [];
371
+ for (var _i = 0; _i < arguments.length; _i++) {
372
+ args[_i] = arguments[_i];
373
+ }
374
+ var errCollection = this.parent.getErrorStrings();
375
+ if (isNullOrUndefined(args) || args.length !== 3) {
376
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
377
+ }
378
+ var p = this.resolveNumberArg(args[0]);
379
+ var alpha = this.resolveNumberArg(args[1]);
380
+ var beta = this.resolveNumberArg(args[2]);
381
+ if (typeof p === 'string') {
382
+ return p;
383
+ }
384
+ if (typeof alpha === 'string') {
385
+ return alpha;
386
+ }
387
+ if (typeof beta === 'string') {
388
+ return beta;
389
+ }
390
+ if (p <= 0 || p >= 1 || alpha <= 0 || beta <= 0) {
391
+ return errCollection[CommonErrors.Num];
392
+ }
393
+ var lo = 0;
394
+ var hi = alpha * beta * 20 + 1;
395
+ for (var i = 0; i < 100; i++) {
396
+ var mid = (lo + hi) / 2;
397
+ if (lowerRegularizedGamma(alpha, mid / beta) < p) {
398
+ lo = mid;
399
+ }
400
+ else {
401
+ hi = mid;
402
+ }
403
+ }
404
+ return ((lo + hi) / 2).toString();
405
+ };
406
+ /**
407
+ * Returns the one-tailed probability of the chi-squared distribution.
408
+ *
409
+ * Excel: `CHIDIST(...)`.
410
+ *
411
+ * @hidden
412
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
413
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
414
+ */
415
+ StatisticalDistributionExtendedFormulas.prototype.ComputeCHIDIST = function () {
416
+ var args = [];
417
+ for (var _i = 0; _i < arguments.length; _i++) {
418
+ args[_i] = arguments[_i];
419
+ }
420
+ if (isNullOrUndefined(args) || args.length !== 2) {
421
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
422
+ }
423
+ var x = this.resolveNumberArg(args[0]);
424
+ var df = this.resolveNumberArg(args[1]);
425
+ if (typeof x === 'string') {
426
+ return x;
427
+ }
428
+ if (typeof df === 'string') {
429
+ return df;
430
+ }
431
+ return (1 - chiSquareCDF(x, df)).toString();
432
+ };
433
+ /**
434
+ * Returns the inverse of the one-tailed probability of the chi-squared distribution.
435
+ *
436
+ * Excel: `CHIINV(...)`.
437
+ *
438
+ * @hidden
439
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
440
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
441
+ */
442
+ StatisticalDistributionExtendedFormulas.prototype.ComputeCHIINV = function () {
443
+ var args = [];
444
+ for (var _i = 0; _i < arguments.length; _i++) {
445
+ args[_i] = arguments[_i];
446
+ }
447
+ if (isNullOrUndefined(args) || args.length !== 2) {
448
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
449
+ }
450
+ var p = this.resolveNumberArg(args[0]);
451
+ var df = this.resolveNumberArg(args[1]);
452
+ if (typeof p === 'string') {
453
+ return p;
454
+ }
455
+ if (typeof df === 'string') {
456
+ return df;
457
+ }
458
+ var result = chiSquareInv(1 - p, df);
459
+ if (isNaN(result)) {
460
+ return this.parent.getErrorStrings()[CommonErrors.Num];
461
+ }
462
+ return result.toString();
463
+ };
464
+ /**
465
+ * Returns the test for independence.
466
+ *
467
+ * Excel: `CHITEST(...)`.
468
+ *
469
+ * @hidden
470
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
471
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
472
+ */
473
+ StatisticalDistributionExtendedFormulas.prototype.ComputeCHITEST = function () {
474
+ var args = [];
475
+ for (var _i = 0; _i < arguments.length; _i++) {
476
+ args[_i] = arguments[_i];
477
+ }
478
+ return this.chiSquareTest(args);
479
+ };
480
+ StatisticalDistributionExtendedFormulas.prototype.chiSquareTest = function (args) {
481
+ var errCollection = this.parent.getErrorStrings();
482
+ if (isNullOrUndefined(args) || args.length !== 2) {
483
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
484
+ }
485
+ var actual = this.collectSample([args[0]], false);
486
+ var expected = this.collectSample([args[1]], false);
487
+ if (typeof actual === 'string') {
488
+ return actual;
489
+ }
490
+ if (typeof expected === 'string') {
491
+ return expected;
492
+ }
493
+ if (actual.length !== expected.length || actual.length === 0) {
494
+ return errCollection[CommonErrors.NA];
495
+ }
496
+ var chi2 = 0;
497
+ for (var i = 0; i < actual.length; i++) {
498
+ if (expected[i] === 0) {
499
+ return errCollection[CommonErrors.DivZero];
500
+ }
501
+ var d = actual[i] - expected[i];
502
+ chi2 += (d * d) / expected[i];
503
+ }
504
+ var df = actual.length - 1;
505
+ return (1 - chiSquareCDF(chi2, df)).toString();
506
+ };
507
+ /**
508
+ * Returns the F probability distribution.
509
+ *
510
+ * Excel: `FDIST(...)`.
511
+ *
512
+ * @hidden
513
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
514
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
515
+ */
516
+ StatisticalDistributionExtendedFormulas.prototype.ComputeFDIST = function () {
517
+ var args = [];
518
+ for (var _i = 0; _i < arguments.length; _i++) {
519
+ args[_i] = arguments[_i];
520
+ }
521
+ if (isNullOrUndefined(args) || args.length !== 3) {
522
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
523
+ }
524
+ var x = this.resolveNumberArg(args[0]);
525
+ var d1 = this.resolveNumberArg(args[1]);
526
+ var d2 = this.resolveNumberArg(args[2]);
527
+ if (typeof x === 'string') {
528
+ return x;
529
+ }
530
+ if (typeof d1 === 'string') {
531
+ return d1;
532
+ }
533
+ if (typeof d2 === 'string') {
534
+ return d2;
535
+ }
536
+ return (1 - fCDF(x, d1, d2)).toString();
537
+ };
538
+ /**
539
+ * Returns the inverse of the F probability distribution.
540
+ *
541
+ * Excel: `FINV(...)`.
542
+ *
543
+ * @hidden
544
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
545
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
546
+ */
547
+ StatisticalDistributionExtendedFormulas.prototype.ComputeFINV = function () {
548
+ var args = [];
549
+ for (var _i = 0; _i < arguments.length; _i++) {
550
+ args[_i] = arguments[_i];
551
+ }
552
+ if (isNullOrUndefined(args) || args.length !== 3) {
553
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
554
+ }
555
+ var p = this.resolveNumberArg(args[0]);
556
+ var d1 = this.resolveNumberArg(args[1]);
557
+ var d2 = this.resolveNumberArg(args[2]);
558
+ if (typeof p === 'string') {
559
+ return p;
560
+ }
561
+ if (typeof d1 === 'string') {
562
+ return d1;
563
+ }
564
+ if (typeof d2 === 'string') {
565
+ return d2;
566
+ }
567
+ var result = fInv(1 - p, d1, d2);
568
+ if (isNaN(result)) {
569
+ return this.parent.getErrorStrings()[CommonErrors.Num];
570
+ }
571
+ return result.toString();
572
+ };
573
+ /**
574
+ * Returns the one-tailed probability-value of a z-test.
575
+ *
576
+ * Excel: `ZTEST(...)`.
577
+ *
578
+ * @hidden
579
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
580
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
581
+ */
582
+ StatisticalDistributionExtendedFormulas.prototype.ComputeZTEST = function () {
583
+ var args = [];
584
+ for (var _i = 0; _i < arguments.length; _i++) {
585
+ args[_i] = arguments[_i];
586
+ }
587
+ var errCollection = this.parent.getErrorStrings();
588
+ if (isNullOrUndefined(args) || args.length < 2 || args.length > 3) {
589
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
590
+ }
591
+ var nums = this.collectSample([args[0]], false);
592
+ if (typeof nums === 'string') {
593
+ return nums;
594
+ }
595
+ if (nums.length < 2) {
596
+ return errCollection[CommonErrors.DivZero];
597
+ }
598
+ var x = this.resolveNumberArg(args[1]);
599
+ if (typeof x === 'string') {
600
+ return x;
601
+ }
602
+ var avg = this.mean(nums);
603
+ var sumSq = 0;
604
+ for (var i = 0; i < nums.length; i++) {
605
+ var d = nums[i] - avg;
606
+ sumSq += d * d;
607
+ }
608
+ var std = Math.sqrt(sumSq / (nums.length - 1));
609
+ if (std === 0) {
610
+ return errCollection[CommonErrors.DivZero];
611
+ }
612
+ var sigma = std / Math.sqrt(nums.length);
613
+ if (args.length === 3) {
614
+ var s = this.resolveNumberArg(args[2]);
615
+ if (typeof s === 'string') {
616
+ return s;
617
+ }
618
+ sigma = s / Math.sqrt(nums.length);
619
+ }
620
+ var z = (avg - x) / sigma;
621
+ return (1 - normCDF(z)).toString();
622
+ };
623
+ /**
624
+ * Returns the probability that values in a range are between two limits.
625
+ *
626
+ * Excel: `PROB(...)`.
627
+ *
628
+ * @hidden
629
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
630
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
631
+ */
632
+ StatisticalDistributionExtendedFormulas.prototype.ComputePROB = function () {
633
+ var args = [];
634
+ for (var _i = 0; _i < arguments.length; _i++) {
635
+ args[_i] = arguments[_i];
636
+ }
637
+ var errCollection = this.parent.getErrorStrings();
638
+ if (isNullOrUndefined(args) || args.length < 3 || args.length > 4) {
639
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
640
+ }
641
+ var nums = this.collectSample([args[0]], false);
642
+ if (typeof nums === 'string') {
643
+ return nums;
644
+ }
645
+ var low = this.resolveNumberArg(args[1]);
646
+ var high = this.resolveNumberArg(args[2]);
647
+ if (typeof low === 'string') {
648
+ return low;
649
+ }
650
+ if (typeof high === 'string') {
651
+ return high;
652
+ }
653
+ if (nums.length === 0) {
654
+ return errCollection[CommonErrors.Num];
655
+ }
656
+ var total = 0;
657
+ var inRange = 0;
658
+ for (var i = 0; i < nums.length; i++) {
659
+ total += 1;
660
+ if (nums[i] >= low && nums[i] <= high) {
661
+ inRange += 1;
662
+ }
663
+ }
664
+ return (inRange / total).toString();
665
+ };
666
+ return StatisticalDistributionExtendedFormulas;
667
+ }(StatisticalSampleBase));
668
+ export { StatisticalDistributionExtendedFormulas };