@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,549 @@
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 { FormulaModuleBase } from './formula-module-base';
17
+ import { parseComplexText, formatComplex } from './formula-math-helpers';
18
+ /**
19
+ * Complex-number arithmetic, polar/rectangular conversion, and complex transcendental functions.
20
+ *
21
+ * Registers 18 functions including COMPLEX, IMABS, IMAGINARY, IMREAL, IMCONJUGATE, and others.
22
+ *
23
+ * @hidden
24
+ */
25
+ var ComplexNumbersFormulas = /** @class */ (function (_super) {
26
+ __extends(ComplexNumbersFormulas, _super);
27
+ /**
28
+ * @hidden
29
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
30
+ */
31
+ function ComplexNumbersFormulas(owner) {
32
+ var _this = _super.call(this, owner) || this;
33
+ /** Formula definitions registered with {@link BasicFormulas}. */
34
+ _this.formulas = [
35
+ { formulaName: 'COMPLEX', category: 'Engineering', description: 'Converts real and imaginary coefficients into a complex number.' },
36
+ { formulaName: 'IMABS', category: 'Engineering', description: 'Returns the absolute value (modulus) of a complex number.' },
37
+ { formulaName: 'IMAGINARY', category: 'Engineering', description: 'Returns the imaginary coefficient of a complex number.' },
38
+ { formulaName: 'IMREAL', category: 'Engineering', description: 'Returns the real coefficient of a complex number.' },
39
+ { formulaName: 'IMCONJUGATE', category: 'Engineering', description: 'Returns the complex conjugate of a complex number.' },
40
+ { formulaName: 'IMSUM', category: 'Engineering', description: 'Returns the sum of complex numbers.' },
41
+ { formulaName: 'IMSUB', category: 'Engineering', description: 'Returns the difference between two complex numbers.' },
42
+ { formulaName: 'IMPRODUCT', category: 'Engineering', description: 'Returns the product of complex numbers.' },
43
+ { formulaName: 'IMDIV', category: 'Engineering', description: 'Returns the quotient of two complex numbers.' },
44
+ { formulaName: 'IMSIN', category: 'Engineering', description: 'Returns the sine of a complex number.' },
45
+ { formulaName: 'IMCOS', category: 'Engineering', description: 'Returns the cosine of a complex number.' },
46
+ { formulaName: 'IMEXP', category: 'Engineering', description: 'Returns the exponential of a complex number.' },
47
+ { formulaName: 'IMLN', category: 'Engineering', description: 'Returns the natural logarithm of a complex number.' },
48
+ { formulaName: 'IMSQRT', category: 'Engineering', description: 'Returns the square root of a complex number.' },
49
+ { formulaName: 'IMPOWER', category: 'Engineering', description: 'Returns a complex number raised to an integer power.' },
50
+ { formulaName: 'IMARGUMENT', category: 'Engineering', description: 'Returns the argument theta of a complex number in radians.' },
51
+ { formulaName: 'IMLOG10', category: 'Engineering', description: 'Returns the base-10 logarithm of a complex number.' },
52
+ { formulaName: 'IMLOG2', category: 'Engineering', description: 'Returns the base-2 logarithm of a complex number.' }
53
+ ];
54
+ return _this;
55
+ }
56
+ ComplexNumbersFormulas.prototype.resolveComplex = function (arg) {
57
+ var errCollection = this.parent.getErrorStrings();
58
+ var text = this.resolveTextArg(arg);
59
+ if (errCollection.indexOf(text) > -1) {
60
+ return text;
61
+ }
62
+ var parsed = parseComplexText(text);
63
+ if (!parsed) {
64
+ return errCollection[CommonErrors.Num];
65
+ }
66
+ return parsed;
67
+ };
68
+ /**
69
+ * Converts real and imaginary coefficients into a complex number.
70
+ *
71
+ * Excel: `COMPLEX(...)`.
72
+ *
73
+ * @hidden
74
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
75
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * engine.computeFormula('=COMPLEX(1)');
80
+ * ```
81
+ */
82
+ ComplexNumbersFormulas.prototype.ComputeCOMPLEX = function () {
83
+ var args = [];
84
+ for (var _i = 0; _i < arguments.length; _i++) {
85
+ args[_i] = arguments[_i];
86
+ }
87
+ if (isNullOrUndefined(args) || args.length < 2 || args.length > 3) {
88
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
89
+ }
90
+ var re = this.resolveNumberArg(args[0]);
91
+ var im = this.resolveNumberArg(args[1]);
92
+ if (typeof re === 'string') {
93
+ return re;
94
+ }
95
+ if (typeof im === 'string') {
96
+ return im;
97
+ }
98
+ var suffix = 'i';
99
+ if (args.length === 3) {
100
+ suffix = this.resolveTextArg(args[2]);
101
+ if (suffix !== 'i' && suffix !== 'j') {
102
+ return this.parent.getErrorStrings()[CommonErrors.Value];
103
+ }
104
+ }
105
+ return formatComplex(re, im, suffix);
106
+ };
107
+ /**
108
+ * Returns the absolute value (modulus) of a complex number.
109
+ *
110
+ * Excel: `IMABS(...)`.
111
+ *
112
+ * @hidden
113
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
114
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
115
+ */
116
+ ComplexNumbersFormulas.prototype.ComputeIMABS = function () {
117
+ var args = [];
118
+ for (var _i = 0; _i < arguments.length; _i++) {
119
+ args[_i] = arguments[_i];
120
+ }
121
+ if (isNullOrUndefined(args) || args.length !== 1) {
122
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
123
+ }
124
+ var c = this.resolveComplex(args[0]);
125
+ if (typeof c === 'string') {
126
+ return c;
127
+ }
128
+ return Math.sqrt(c.re * c.re + c.im * c.im).toString();
129
+ };
130
+ /**
131
+ * Returns the imaginary coefficient of a complex number.
132
+ *
133
+ * Excel: `IMAGINARY(...)`.
134
+ *
135
+ * @hidden
136
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
137
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
138
+ */
139
+ ComplexNumbersFormulas.prototype.ComputeIMAGINARY = function () {
140
+ var args = [];
141
+ for (var _i = 0; _i < arguments.length; _i++) {
142
+ args[_i] = arguments[_i];
143
+ }
144
+ if (isNullOrUndefined(args) || args.length !== 1) {
145
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
146
+ }
147
+ var c = this.resolveComplex(args[0]);
148
+ if (typeof c === 'string') {
149
+ return c;
150
+ }
151
+ return c.im.toString();
152
+ };
153
+ /**
154
+ * Returns the real coefficient of a complex number.
155
+ *
156
+ * Excel: `IMREAL(...)`.
157
+ *
158
+ * @hidden
159
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
160
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
161
+ */
162
+ ComplexNumbersFormulas.prototype.ComputeIMREAL = function () {
163
+ var args = [];
164
+ for (var _i = 0; _i < arguments.length; _i++) {
165
+ args[_i] = arguments[_i];
166
+ }
167
+ if (isNullOrUndefined(args) || args.length !== 1) {
168
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
169
+ }
170
+ var c = this.resolveComplex(args[0]);
171
+ if (typeof c === 'string') {
172
+ return c;
173
+ }
174
+ return c.re.toString();
175
+ };
176
+ /**
177
+ * Returns the complex conjugate of a complex number.
178
+ *
179
+ * Excel: `IMCONJUGATE(...)`.
180
+ *
181
+ * @hidden
182
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
183
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
184
+ */
185
+ ComplexNumbersFormulas.prototype.ComputeIMCONJUGATE = function () {
186
+ var args = [];
187
+ for (var _i = 0; _i < arguments.length; _i++) {
188
+ args[_i] = arguments[_i];
189
+ }
190
+ if (isNullOrUndefined(args) || args.length !== 1) {
191
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
192
+ }
193
+ var c = this.resolveComplex(args[0]);
194
+ if (typeof c === 'string') {
195
+ return c;
196
+ }
197
+ return formatComplex(c.re, -c.im);
198
+ };
199
+ /**
200
+ * Returns the sum of complex numbers.
201
+ *
202
+ * Excel: `IMSUM(...)`.
203
+ *
204
+ *
205
+ * @hidden
206
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
207
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
208
+ */
209
+ ComplexNumbersFormulas.prototype.ComputeIMSUM = function () {
210
+ var args = [];
211
+ for (var _i = 0; _i < arguments.length; _i++) {
212
+ args[_i] = arguments[_i];
213
+ }
214
+ return this.complexReduce(args, function (a, b) { return ({ re: a.re + b.re, im: a.im + b.im }); });
215
+ };
216
+ /**
217
+ * Returns the difference between two complex numbers.
218
+ *
219
+ * Excel: `IMSUB(...)`.
220
+ *
221
+ * @hidden
222
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
223
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
224
+ */
225
+ ComplexNumbersFormulas.prototype.ComputeIMSUB = function () {
226
+ var args = [];
227
+ for (var _i = 0; _i < arguments.length; _i++) {
228
+ args[_i] = arguments[_i];
229
+ }
230
+ if (isNullOrUndefined(args) || args.length !== 2) {
231
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
232
+ }
233
+ var a = this.resolveComplex(args[0]);
234
+ var b = this.resolveComplex(args[1]);
235
+ if (typeof a === 'string') {
236
+ return a;
237
+ }
238
+ if (typeof b === 'string') {
239
+ return b;
240
+ }
241
+ return formatComplex(a.re - b.re, a.im - b.im);
242
+ };
243
+ /**
244
+ * Returns the product of complex numbers.
245
+ *
246
+ * Excel: `IMPRODUCT(...)`.
247
+ *
248
+ * @hidden
249
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
250
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
251
+ */
252
+ ComplexNumbersFormulas.prototype.ComputeIMPRODUCT = function () {
253
+ var args = [];
254
+ for (var _i = 0; _i < arguments.length; _i++) {
255
+ args[_i] = arguments[_i];
256
+ }
257
+ return this.complexReduce(args, function (a, b) { return ({
258
+ re: a.re * b.re - a.im * b.im,
259
+ im: a.re * b.im + a.im * b.re
260
+ }); }, { re: 1, im: 0 });
261
+ };
262
+ /**
263
+ * Returns the quotient of two complex numbers.
264
+ *
265
+ * Excel: `IMDIV(...)`.
266
+ *
267
+ * @hidden
268
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
269
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
270
+ */
271
+ ComplexNumbersFormulas.prototype.ComputeIMDIV = function () {
272
+ var args = [];
273
+ for (var _i = 0; _i < arguments.length; _i++) {
274
+ args[_i] = arguments[_i];
275
+ }
276
+ var errCollection = this.parent.getErrorStrings();
277
+ if (isNullOrUndefined(args) || args.length !== 2) {
278
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
279
+ }
280
+ var a = this.resolveComplex(args[0]);
281
+ var b = this.resolveComplex(args[1]);
282
+ if (typeof a === 'string') {
283
+ return a;
284
+ }
285
+ if (typeof b === 'string') {
286
+ return b;
287
+ }
288
+ var denom = b.re * b.re + b.im * b.im;
289
+ if (denom === 0) {
290
+ return errCollection[CommonErrors.DivZero];
291
+ }
292
+ return formatComplex((a.re * b.re + a.im * b.im) / denom, (a.im * b.re - a.re * b.im) / denom);
293
+ };
294
+ ComplexNumbersFormulas.prototype.complexReduce = function (args, fn, initial) {
295
+ if (isNullOrUndefined(args) || args.length < 1) {
296
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
297
+ }
298
+ var acc = initial !== undefined ? initial : this.resolveComplex(args[0]);
299
+ if (typeof acc === 'string') {
300
+ return acc;
301
+ }
302
+ var start = initial ? 0 : 1;
303
+ for (var i = start; i < args.length; i++) {
304
+ var b = this.resolveComplex(args[i]);
305
+ if (typeof b === 'string') {
306
+ return b;
307
+ }
308
+ acc = fn(acc, b);
309
+ }
310
+ return formatComplex(acc.re, acc.im);
311
+ };
312
+ /**
313
+ * Returns the exponential of a complex number.
314
+ *
315
+ * Excel: `IMEXP(...)`.
316
+ *
317
+ * @hidden
318
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
319
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
320
+ */
321
+ ComplexNumbersFormulas.prototype.ComputeIMEXP = function () {
322
+ var args = [];
323
+ for (var _i = 0; _i < arguments.length; _i++) {
324
+ args[_i] = arguments[_i];
325
+ }
326
+ if (isNullOrUndefined(args) || args.length !== 1) {
327
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
328
+ }
329
+ var c = this.resolveComplex(args[0]);
330
+ if (typeof c === 'string') {
331
+ return c;
332
+ }
333
+ var expRe = Math.exp(c.re);
334
+ return formatComplex(expRe * Math.cos(c.im), expRe * Math.sin(c.im));
335
+ };
336
+ /**
337
+ * Returns the natural logarithm of a complex number.
338
+ *
339
+ * Excel: `IMLN(...)`.
340
+ *
341
+ * @hidden
342
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
343
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
344
+ */
345
+ ComplexNumbersFormulas.prototype.ComputeIMLN = function () {
346
+ var args = [];
347
+ for (var _i = 0; _i < arguments.length; _i++) {
348
+ args[_i] = arguments[_i];
349
+ }
350
+ if (isNullOrUndefined(args) || args.length !== 1) {
351
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
352
+ }
353
+ var c = this.resolveComplex(args[0]);
354
+ if (typeof c === 'string') {
355
+ return c;
356
+ }
357
+ var r = Math.sqrt(c.re * c.re + c.im * c.im);
358
+ if (r === 0) {
359
+ return this.parent.getErrorStrings()[CommonErrors.Num];
360
+ }
361
+ return formatComplex(Math.log(r), Math.atan2(c.im, c.re));
362
+ };
363
+ /**
364
+ * Returns the base-10 logarithm of a complex number.
365
+ *
366
+ * Excel: `IMLOG10(...)`.
367
+ *
368
+ * @hidden
369
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
370
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
371
+ */
372
+ ComplexNumbersFormulas.prototype.ComputeIMLOG10 = function () {
373
+ var args = [];
374
+ for (var _i = 0; _i < arguments.length; _i++) {
375
+ args[_i] = arguments[_i];
376
+ }
377
+ var ln = this.ComputeIMLN.apply(this, args);
378
+ if (typeof ln === 'string' && this.parent.getErrorStrings().indexOf(ln) > -1) {
379
+ return ln;
380
+ }
381
+ var c = parseComplexText(ln.toString());
382
+ if (!c) {
383
+ return ln;
384
+ }
385
+ var log10e = 1 / Math.LN10;
386
+ return formatComplex(c.re * log10e, c.im * log10e);
387
+ };
388
+ /**
389
+ * Returns the base-2 logarithm of a complex number.
390
+ *
391
+ * Excel: `IMLOG2(...)`.
392
+ *
393
+ * @hidden
394
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
395
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
396
+ */
397
+ ComplexNumbersFormulas.prototype.ComputeIMLOG2 = function () {
398
+ var args = [];
399
+ for (var _i = 0; _i < arguments.length; _i++) {
400
+ args[_i] = arguments[_i];
401
+ }
402
+ var ln = this.ComputeIMLN.apply(this, args);
403
+ if (typeof ln === 'string' && this.parent.getErrorStrings().indexOf(ln) > -1) {
404
+ return ln;
405
+ }
406
+ var c = parseComplexText(ln.toString());
407
+ if (!c) {
408
+ return ln;
409
+ }
410
+ var log2e = 1 / Math.LN2;
411
+ return formatComplex(c.re * log2e, c.im * log2e);
412
+ };
413
+ /**
414
+ * Returns the square root of a complex number.
415
+ *
416
+ * Excel: `IMSQRT(...)`.
417
+ *
418
+ * @hidden
419
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
420
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
421
+ */
422
+ ComplexNumbersFormulas.prototype.ComputeIMSQRT = function () {
423
+ var args = [];
424
+ for (var _i = 0; _i < arguments.length; _i++) {
425
+ args[_i] = arguments[_i];
426
+ }
427
+ if (isNullOrUndefined(args) || args.length !== 1) {
428
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
429
+ }
430
+ var c = this.resolveComplex(args[0]);
431
+ if (typeof c === 'string') {
432
+ return c;
433
+ }
434
+ var r = Math.sqrt(c.re * c.re + c.im * c.im);
435
+ var theta = Math.atan2(c.im, c.re);
436
+ var sqrtR = Math.sqrt(r);
437
+ return formatComplex(sqrtR * Math.cos(theta / 2), sqrtR * Math.sin(theta / 2));
438
+ };
439
+ /**
440
+ * Returns a complex number raised to an integer power.
441
+ *
442
+ * Excel: `IMPOWER(...)`.
443
+ *
444
+ * @hidden
445
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
446
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
447
+ */
448
+ ComplexNumbersFormulas.prototype.ComputeIMPOWER = function () {
449
+ var args = [];
450
+ for (var _i = 0; _i < arguments.length; _i++) {
451
+ args[_i] = arguments[_i];
452
+ }
453
+ var errCollection = this.parent.getErrorStrings();
454
+ if (isNullOrUndefined(args) || args.length !== 2) {
455
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
456
+ }
457
+ var c = this.resolveComplex(args[0]);
458
+ var nArg = this.resolveNumberArg(args[1]);
459
+ if (typeof c === 'string') {
460
+ return c;
461
+ }
462
+ if (typeof nArg === 'string') {
463
+ return nArg;
464
+ }
465
+ var n = Math.floor(nArg);
466
+ var r = Math.sqrt(c.re * c.re + c.im * c.im);
467
+ if (r === 0 && n <= 0) {
468
+ return errCollection[CommonErrors.Num];
469
+ }
470
+ var theta = Math.atan2(c.im, c.re);
471
+ var rn = Math.pow(r, n);
472
+ var angle = n * theta;
473
+ return formatComplex(rn * Math.cos(angle), rn * Math.sin(angle));
474
+ };
475
+ /**
476
+ * Returns the argument theta of a complex number in radians.
477
+ *
478
+ * Excel: `IMARGUMENT(...)`.
479
+ *
480
+ * @hidden
481
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
482
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
483
+ */
484
+ ComplexNumbersFormulas.prototype.ComputeIMARGUMENT = function () {
485
+ var args = [];
486
+ for (var _i = 0; _i < arguments.length; _i++) {
487
+ args[_i] = arguments[_i];
488
+ }
489
+ if (isNullOrUndefined(args) || args.length !== 1) {
490
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
491
+ }
492
+ var c = this.resolveComplex(args[0]);
493
+ if (typeof c === 'string') {
494
+ return c;
495
+ }
496
+ if (c.re === 0 && c.im === 0) {
497
+ return this.parent.getErrorStrings()[CommonErrors.DivZero];
498
+ }
499
+ return Math.atan2(c.im, c.re).toString();
500
+ };
501
+ /**
502
+ * Returns the sine of a complex number.
503
+ *
504
+ * Excel: `IMSIN(...)`.
505
+ *
506
+ * @hidden
507
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
508
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
509
+ */
510
+ ComplexNumbersFormulas.prototype.ComputeIMSIN = function () {
511
+ var args = [];
512
+ for (var _i = 0; _i < arguments.length; _i++) {
513
+ args[_i] = arguments[_i];
514
+ }
515
+ if (isNullOrUndefined(args) || args.length !== 1) {
516
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
517
+ }
518
+ var c = this.resolveComplex(args[0]);
519
+ if (typeof c === 'string') {
520
+ return c;
521
+ }
522
+ return formatComplex(Math.sin(c.re) * Math.cosh(c.im), Math.cos(c.re) * Math.sinh(c.im));
523
+ };
524
+ /**
525
+ * Returns the cosine of a complex number.
526
+ *
527
+ * Excel: `IMCOS(...)`.
528
+ *
529
+ * @hidden
530
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
531
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
532
+ */
533
+ ComplexNumbersFormulas.prototype.ComputeIMCOS = function () {
534
+ var args = [];
535
+ for (var _i = 0; _i < arguments.length; _i++) {
536
+ args[_i] = arguments[_i];
537
+ }
538
+ if (isNullOrUndefined(args) || args.length !== 1) {
539
+ return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
540
+ }
541
+ var c = this.resolveComplex(args[0]);
542
+ if (typeof c === 'string') {
543
+ return c;
544
+ }
545
+ return formatComplex(Math.cos(c.re) * Math.cosh(c.im), -Math.sin(c.re) * Math.sinh(c.im));
546
+ };
547
+ return ComplexNumbersFormulas;
548
+ }(FormulaModuleBase));
549
+ export { ComplexNumbersFormulas };
@@ -0,0 +1,152 @@
1
+ import { IBasicFormula } from '../common/index';
2
+ import { FormulaOwner } from './formula-owner';
3
+ import { FormulaModuleBase } from './formula-module-base';
4
+ /**
5
+ * Database-style conditional aggregates (DSUM, DCOUNT, DGET) over structured table ranges.
6
+ *
7
+ * Registers 12 functions including DAVERAGE, DCOUNT, DCOUNTA, DGET, DMAX, and others.
8
+ *
9
+ * @hidden
10
+ */
11
+ export declare class DatabaseFormulas extends FormulaModuleBase {
12
+ /** Formula definitions registered with {@link BasicFormulas}. */
13
+ formulas: IBasicFormula[];
14
+ /**
15
+ * @hidden
16
+ * @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
17
+ */
18
+ constructor(owner: FormulaOwner);
19
+ private readRange;
20
+ private fieldIndex;
21
+ private matchCriteria;
22
+ private matchesCriterion;
23
+ private collectMatching;
24
+ private requireThree;
25
+ private mean;
26
+ private variance;
27
+ /**
28
+ * Averages the values in a column of a list or database that match criteria.
29
+ *
30
+ * Excel: `DAVERAGE(...)`.
31
+ *
32
+ * @hidden
33
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
34
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * engine.computeFormula('=DAVERAGE(1)');
39
+ * ```
40
+ */
41
+ ComputeDAVERAGE(...args: string[]): string | number;
42
+ /**
43
+ * Counts the cells that contain numbers in a column of a list or database that match criteria.
44
+ *
45
+ * Excel: `DCOUNT(...)`.
46
+ *
47
+ * @hidden
48
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
49
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
50
+ */
51
+ ComputeDCOUNT(...args: string[]): string | number;
52
+ /**
53
+ * Counts nonblank cells in a column of a list or database that match criteria.
54
+ *
55
+ * Excel: `DCOUNTA(...)`.
56
+ *
57
+ * @hidden
58
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
59
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
60
+ */
61
+ ComputeDCOUNTA(...args: string[]): string | number;
62
+ /**
63
+ * Extracts a single value from a column of a list or database that matches criteria.
64
+ *
65
+ * Excel: `DGET(...)`.
66
+ *
67
+ * @hidden
68
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
69
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
70
+ */
71
+ ComputeDGET(...args: string[]): string | number;
72
+ /**
73
+ * Returns the maximum value from a column of a list or database that matches criteria.
74
+ *
75
+ * Excel: `DMAX(...)`.
76
+ *
77
+ * @hidden
78
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
79
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
80
+ */
81
+ ComputeDMAX(...args: string[]): string | number;
82
+ /**
83
+ * Returns the minimum value from a column of a list or database that matches criteria.
84
+ *
85
+ * Excel: `DMIN(...)`.
86
+ *
87
+ * @hidden
88
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
89
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
90
+ */
91
+ ComputeDMIN(...args: string[]): string | number;
92
+ /**
93
+ * Multiplies values in a column of a list or database that match criteria.
94
+ *
95
+ * Excel: `DPRODUCT(...)`.
96
+ *
97
+ * @hidden
98
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
99
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
100
+ */
101
+ ComputeDPRODUCT(...args: string[]): string | number;
102
+ /**
103
+ * Adds the numbers in the field column of records in the database that match the criteria.
104
+ *
105
+ * Excel: `DSUM(...)`.
106
+ *
107
+ * @hidden
108
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
109
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
110
+ */
111
+ ComputeDSUM(...args: string[]): string | number;
112
+ /**
113
+ * Estimates the standard deviation of a population based on a sample of entries that match criteria.
114
+ *
115
+ * Excel: `DSTDEV(...)`.
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
+ ComputeDSTDEV(...args: string[]): string | number;
122
+ /**
123
+ * Calculates the standard deviation of a population based on entries that match criteria.
124
+ *
125
+ * Excel: `DSTDEVP(...)`.
126
+ *
127
+ * @hidden
128
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
129
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
130
+ */
131
+ ComputeDSTDEVP(...args: string[]): string | number;
132
+ /**
133
+ * Estimates variance based on a sample of entries that match criteria.
134
+ *
135
+ * Excel: `DVAR(...)`.
136
+ *
137
+ * @hidden
138
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
139
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
140
+ */
141
+ ComputeDVAR(...args: string[]): string | number;
142
+ /**
143
+ * Calculates variance based on the entire population of entries that match criteria.
144
+ *
145
+ * Excel: `DVARP(...)`.
146
+ *
147
+ * @hidden
148
+ * @param {string[]} args - Formula argument tokens from the Calculate engine.
149
+ * @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
150
+ */
151
+ ComputeDVARP(...args: string[]): string | number;
152
+ }