@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.
- package/.eslintrc.json +263 -0
- package/README.md +132 -0
- package/base.d.ts +4 -0
- package/base.js +4 -0
- package/common.d.ts +4 -0
- package/common.js +4 -0
- package/dist/ej2-calculate.umd.min.js +11 -0
- package/dist/ej2-calculate.umd.min.js.map +1 -0
- package/dist/es6/ej2-calculate.es2015.js +24801 -0
- package/dist/es6/ej2-calculate.es2015.js.map +1 -0
- package/dist/es6/ej2-calculate.es5.js +27229 -0
- package/dist/es6/ej2-calculate.es5.js.map +1 -0
- package/dist/global/ej2-calculate.min.js +11 -0
- package/dist/global/ej2-calculate.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/formulas.d.ts +4 -0
- package/formulas.js +4 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/license +10 -0
- package/package.json +30 -0
- package/src/base/calculate-model.d.ts +4 -0
- package/src/base/calculate-model.js +0 -0
- package/src/base/calculate.d.ts +1105 -0
- package/src/base/calculate.js +4720 -0
- package/src/base/index.d.ts +8 -0
- package/src/base/index.js +7 -0
- package/src/base/parser.d.ts +208 -0
- package/src/base/parser.js +1512 -0
- package/src/common/address.d.ts +59 -0
- package/src/common/address.js +96 -0
- package/src/common/cell-ref.d.ts +32 -0
- package/src/common/cell-ref.js +112 -0
- package/src/common/common.d.ts +44 -0
- package/src/common/common.js +134 -0
- package/src/common/enum.d.ts +94 -0
- package/src/common/enum.js +97 -0
- package/src/common/index.d.ts +9 -0
- package/src/common/index.js +8 -0
- package/src/common/interface.d.ts +122 -0
- package/src/common/interface.js +0 -0
- package/src/common/l10n.d.ts +24 -0
- package/src/common/l10n.js +54 -0
- package/src/common/number-date.d.ts +26 -0
- package/src/common/number-date.js +38 -0
- package/src/common/sheet-info.d.ts +10 -0
- package/src/common/sheet-info.js +17 -0
- package/src/common/sort.d.ts +17 -0
- package/src/common/sort.js +44 -0
- package/src/formulas/array.d.ts +47 -0
- package/src/formulas/array.js +718 -0
- package/src/formulas/basic.d.ts +47 -0
- package/src/formulas/basic.js +181 -0
- package/src/formulas/complex-numbers.d.ts +207 -0
- package/src/formulas/complex-numbers.js +549 -0
- package/src/formulas/database.d.ts +152 -0
- package/src/formulas/database.js +579 -0
- package/src/formulas/date-time-extra.d.ts +97 -0
- package/src/formulas/date-time-extra.js +415 -0
- package/src/formulas/date-time-intl.d.ts +57 -0
- package/src/formulas/date-time-intl.js +309 -0
- package/src/formulas/date-time.d.ts +164 -0
- package/src/formulas/date-time.js +1021 -0
- package/src/formulas/engineering-base.d.ts +150 -0
- package/src/formulas/engineering-base.js +404 -0
- package/src/formulas/engineering-bessel.d.ts +65 -0
- package/src/formulas/engineering-bessel.js +167 -0
- package/src/formulas/engineering-convert.d.ts +35 -0
- package/src/formulas/engineering-convert.js +120 -0
- package/src/formulas/engineering-misc.d.ts +64 -0
- package/src/formulas/engineering-misc.js +168 -0
- package/src/formulas/financial-amortization-ecma.d.ts +87 -0
- package/src/formulas/financial-amortization-ecma.js +288 -0
- package/src/formulas/financial-annuity.d.ts +104 -0
- package/src/formulas/financial-annuity.js +419 -0
- package/src/formulas/financial-bond-helpers.d.ts +106 -0
- package/src/formulas/financial-bond-helpers.js +190 -0
- package/src/formulas/financial-cashflow.d.ts +47 -0
- package/src/formulas/financial-cashflow.js +203 -0
- package/src/formulas/financial-coupons.d.ts +227 -0
- package/src/formulas/financial-coupons.js +810 -0
- package/src/formulas/financial-depreciation.d.ts +64 -0
- package/src/formulas/financial-depreciation.js +247 -0
- package/src/formulas/financial-rates.d.ts +54 -0
- package/src/formulas/financial-rates.js +140 -0
- package/src/formulas/financial-securities.d.ts +126 -0
- package/src/formulas/financial-securities.js +488 -0
- package/src/formulas/formula-math-helpers.d.ts +212 -0
- package/src/formulas/formula-math-helpers.js +599 -0
- package/src/formulas/formula-module-base.d.ts +54 -0
- package/src/formulas/formula-module-base.js +125 -0
- package/src/formulas/formula-owner.d.ts +17 -0
- package/src/formulas/formula-owner.js +0 -0
- package/src/formulas/index.d.ts +68 -0
- package/src/formulas/index.js +67 -0
- package/src/formulas/information-advanced.d.ts +44 -0
- package/src/formulas/information-advanced.js +157 -0
- package/src/formulas/information-ecma.d.ts +33 -0
- package/src/formulas/information-ecma.js +88 -0
- package/src/formulas/information-extra.d.ts +146 -0
- package/src/formulas/information-extra.js +351 -0
- package/src/formulas/information.d.ts +34 -0
- package/src/formulas/information.js +78 -0
- package/src/formulas/logical-extra.d.ts +75 -0
- package/src/formulas/logical-extra.js +217 -0
- package/src/formulas/logical.d.ts +83 -0
- package/src/formulas/logical.js +296 -0
- package/src/formulas/lookup-array.d.ts +98 -0
- package/src/formulas/lookup-array.js +364 -0
- package/src/formulas/lookup-ref-extra.d.ts +64 -0
- package/src/formulas/lookup-ref-extra.js +180 -0
- package/src/formulas/lookup-ref.d.ts +84 -0
- package/src/formulas/lookup-ref.js +263 -0
- package/src/formulas/lookup.d.ts +114 -0
- package/src/formulas/lookup.js +881 -0
- package/src/formulas/math-aggregate.d.ts +74 -0
- package/src/formulas/math-aggregate.js +376 -0
- package/src/formulas/math-ceiling-ecma.d.ts +42 -0
- package/src/formulas/math-ceiling-ecma.js +123 -0
- package/src/formulas/math-combinatorics.d.ts +75 -0
- package/src/formulas/math-combinatorics.js +290 -0
- package/src/formulas/math-misc.d.ts +164 -0
- package/src/formulas/math-misc.js +889 -0
- package/src/formulas/math-number.d.ts +76 -0
- package/src/formulas/math-number.js +261 -0
- package/src/formulas/math-rounding.d.ts +115 -0
- package/src/formulas/math-rounding.js +728 -0
- package/src/formulas/math-trig-hyperbolic.d.ts +55 -0
- package/src/formulas/math-trig-hyperbolic.js +113 -0
- package/src/formulas/math-trig.d.ts +165 -0
- package/src/formulas/math-trig.js +334 -0
- package/src/formulas/matrix-base.d.ts +13 -0
- package/src/formulas/matrix-base.js +169 -0
- package/src/formulas/matrix.d.ts +64 -0
- package/src/formulas/matrix.js +161 -0
- package/src/formulas/regression-ecma.d.ts +66 -0
- package/src/formulas/regression-ecma.js +234 -0
- package/src/formulas/statistical-advanced.d.ts +125 -0
- package/src/formulas/statistical-advanced.js +756 -0
- package/src/formulas/statistical-correlation.d.ts +75 -0
- package/src/formulas/statistical-correlation.js +198 -0
- package/src/formulas/statistical-dispersion.d.ts +108 -0
- package/src/formulas/statistical-dispersion.js +337 -0
- package/src/formulas/statistical-distribution-extended.d.ts +176 -0
- package/src/formulas/statistical-distribution-extended.js +668 -0
- package/src/formulas/statistical-distribution.d.ts +104 -0
- package/src/formulas/statistical-distribution.js +368 -0
- package/src/formulas/statistical-ecma.d.ts +95 -0
- package/src/formulas/statistical-ecma.js +392 -0
- package/src/formulas/statistical-extended.d.ts +136 -0
- package/src/formulas/statistical-extended.js +340 -0
- package/src/formulas/statistical-ifs.d.ts +46 -0
- package/src/formulas/statistical-ifs.js +180 -0
- package/src/formulas/statistical-moments.d.ts +84 -0
- package/src/formulas/statistical-moments.js +269 -0
- package/src/formulas/statistical-percentile.d.ts +56 -0
- package/src/formulas/statistical-percentile.js +195 -0
- package/src/formulas/statistical-sample-base.d.ts +14 -0
- package/src/formulas/statistical-sample-base.js +124 -0
- package/src/formulas/statistical.d.ts +135 -0
- package/src/formulas/statistical.js +542 -0
- package/src/formulas/text-advanced.d.ts +64 -0
- package/src/formulas/text-advanced.js +222 -0
- package/src/formulas/text-ecma.d.ts +54 -0
- package/src/formulas/text-ecma.js +106 -0
- package/src/formulas/text-extra.d.ts +216 -0
- package/src/formulas/text-extra.js +657 -0
- package/src/formulas/text.d.ts +125 -0
- package/src/formulas/text.js +628 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +14 -0
- package/tslint.json +111 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { IBasicFormula } from '../common/index';
|
|
2
|
+
import { FormulaOwner } from './formula-owner';
|
|
3
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
4
|
+
/**
|
|
5
|
+
* Foundational engineering conversions and numeric transforms used in scientific worksheets.
|
|
6
|
+
*
|
|
7
|
+
* Registers 12 functions including BIN2DEC, BIN2HEX, BIN2OCT, DEC2BIN, DEC2HEX, and others.
|
|
8
|
+
*
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export declare class EngineeringBaseFormulas 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 parseBaseNumber;
|
|
20
|
+
private resolveBaseArg;
|
|
21
|
+
private formatToBase;
|
|
22
|
+
/**
|
|
23
|
+
* Converts a binary number to decimal.
|
|
24
|
+
*
|
|
25
|
+
* Excel: `BIN2DEC(...)`.
|
|
26
|
+
*
|
|
27
|
+
* @hidden
|
|
28
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
29
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* engine.computeFormula('=BIN2DEC(1)');
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
ComputeBIN2DEC(...args: string[]): string | number;
|
|
37
|
+
/**
|
|
38
|
+
* Converts a binary number to hexadecimal.
|
|
39
|
+
*
|
|
40
|
+
* Excel: `BIN2HEX(...)`.
|
|
41
|
+
*
|
|
42
|
+
* @hidden
|
|
43
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
44
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
45
|
+
*/
|
|
46
|
+
ComputeBIN2HEX(...args: string[]): string | number;
|
|
47
|
+
/**
|
|
48
|
+
* Converts a binary number to octal.
|
|
49
|
+
*
|
|
50
|
+
* Excel: `BIN2OCT(...)`.
|
|
51
|
+
*
|
|
52
|
+
* @hidden
|
|
53
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
54
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
55
|
+
*/
|
|
56
|
+
ComputeBIN2OCT(...args: string[]): string | number;
|
|
57
|
+
private binTo;
|
|
58
|
+
/**
|
|
59
|
+
* Converts a decimal number to binary.
|
|
60
|
+
*
|
|
61
|
+
* Excel: `DEC2BIN(...)`.
|
|
62
|
+
*
|
|
63
|
+
* @hidden
|
|
64
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
65
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
66
|
+
*/
|
|
67
|
+
ComputeDEC2BIN(...args: string[]): string | number;
|
|
68
|
+
/**
|
|
69
|
+
* Converts a decimal number to hexadecimal.
|
|
70
|
+
*
|
|
71
|
+
* Excel: `DEC2HEX(...)`.
|
|
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
|
+
ComputeDEC2HEX(...args: string[]): string | number;
|
|
78
|
+
/**
|
|
79
|
+
* Converts a decimal number to octal.
|
|
80
|
+
*
|
|
81
|
+
* Excel: `DEC2OCT(...)`.
|
|
82
|
+
*
|
|
83
|
+
* @hidden
|
|
84
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
85
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
86
|
+
*/
|
|
87
|
+
ComputeDEC2OCT(...args: string[]): string | number;
|
|
88
|
+
private decTo;
|
|
89
|
+
/**
|
|
90
|
+
* Converts a hexadecimal number to decimal.
|
|
91
|
+
*
|
|
92
|
+
* Excel: `HEX2DEC(...)`.
|
|
93
|
+
*
|
|
94
|
+
* @hidden
|
|
95
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
96
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
97
|
+
*/
|
|
98
|
+
ComputeHEX2DEC(...args: string[]): string | number;
|
|
99
|
+
/**
|
|
100
|
+
* Converts a hexadecimal number to binary.
|
|
101
|
+
*
|
|
102
|
+
* Excel: `HEX2BIN(...)`.
|
|
103
|
+
*
|
|
104
|
+
* @hidden
|
|
105
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
106
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
107
|
+
*/
|
|
108
|
+
ComputeHEX2BIN(...args: string[]): string | number;
|
|
109
|
+
/**
|
|
110
|
+
* Converts a hexadecimal number to octal.
|
|
111
|
+
*
|
|
112
|
+
* Excel: `HEX2OCT(...)`.
|
|
113
|
+
*
|
|
114
|
+
* @hidden
|
|
115
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
116
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
117
|
+
*/
|
|
118
|
+
ComputeHEX2OCT(...args: string[]): string | number;
|
|
119
|
+
/**
|
|
120
|
+
* Converts an octal number to decimal.
|
|
121
|
+
*
|
|
122
|
+
* Excel: `OCT2DEC(...)`.
|
|
123
|
+
*
|
|
124
|
+
* @hidden
|
|
125
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
126
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
127
|
+
*/
|
|
128
|
+
ComputeOCT2DEC(...args: string[]): string | number;
|
|
129
|
+
/**
|
|
130
|
+
* Converts an octal number to binary.
|
|
131
|
+
*
|
|
132
|
+
* Excel: `OCT2BIN(...)`.
|
|
133
|
+
*
|
|
134
|
+
* @hidden
|
|
135
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
136
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
137
|
+
*/
|
|
138
|
+
ComputeOCT2BIN(...args: string[]): string | number;
|
|
139
|
+
/**
|
|
140
|
+
* Converts an octal number to hexadecimal.
|
|
141
|
+
*
|
|
142
|
+
* Excel: `OCT2HEX(...)`.
|
|
143
|
+
*
|
|
144
|
+
* @hidden
|
|
145
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
146
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
147
|
+
*/
|
|
148
|
+
ComputeOCT2HEX(...args: string[]): string | number;
|
|
149
|
+
private hexOctTo;
|
|
150
|
+
}
|
|
@@ -0,0 +1,404 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* Foundational engineering conversions and numeric transforms used in scientific worksheets.
|
|
19
|
+
*
|
|
20
|
+
* Registers 12 functions including BIN2DEC, BIN2HEX, BIN2OCT, DEC2BIN, DEC2HEX, and others.
|
|
21
|
+
*
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
var EngineeringBaseFormulas = /** @class */ (function (_super) {
|
|
25
|
+
__extends(EngineeringBaseFormulas, _super);
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
* @param {FormulaOwner} owner - Formula registration owner ({@link BasicFormulas}).
|
|
29
|
+
*/
|
|
30
|
+
function EngineeringBaseFormulas(owner) {
|
|
31
|
+
var _this = _super.call(this, owner) || this;
|
|
32
|
+
/** Formula definitions registered with {@link BasicFormulas}. */
|
|
33
|
+
_this.formulas = [
|
|
34
|
+
{ formulaName: 'BIN2DEC', category: 'Engineering', description: 'Converts a binary number to decimal.' },
|
|
35
|
+
{ formulaName: 'BIN2HEX', category: 'Engineering', description: 'Converts a binary number to hexadecimal.' },
|
|
36
|
+
{ formulaName: 'BIN2OCT', category: 'Engineering', description: 'Converts a binary number to octal.' },
|
|
37
|
+
{ formulaName: 'DEC2BIN', category: 'Engineering', description: 'Converts a decimal number to binary.' },
|
|
38
|
+
{ formulaName: 'DEC2HEX', category: 'Engineering', description: 'Converts a decimal number to hexadecimal.' },
|
|
39
|
+
{ formulaName: 'DEC2OCT', category: 'Engineering', description: 'Converts a decimal number to octal.' },
|
|
40
|
+
{ formulaName: 'HEX2BIN', category: 'Engineering', description: 'Converts a hexadecimal number to binary.' },
|
|
41
|
+
{ formulaName: 'HEX2DEC', category: 'Engineering', description: 'Converts a hexadecimal number to decimal.' },
|
|
42
|
+
{ formulaName: 'HEX2OCT', category: 'Engineering', description: 'Converts a hexadecimal number to octal.' },
|
|
43
|
+
{ formulaName: 'OCT2BIN', category: 'Engineering', description: 'Converts an octal number to binary.' },
|
|
44
|
+
{ formulaName: 'OCT2DEC', category: 'Engineering', description: 'Converts an octal number to decimal.' },
|
|
45
|
+
{ formulaName: 'OCT2HEX', category: 'Engineering', description: 'Converts an octal number to hexadecimal.' }
|
|
46
|
+
];
|
|
47
|
+
return _this;
|
|
48
|
+
}
|
|
49
|
+
EngineeringBaseFormulas.prototype.parseBaseNumber = function (text, base) {
|
|
50
|
+
var errCollection = this.parent.getErrorStrings();
|
|
51
|
+
var cleaned = text.trim().toUpperCase();
|
|
52
|
+
if (cleaned === '') {
|
|
53
|
+
return errCollection[CommonErrors.Num];
|
|
54
|
+
}
|
|
55
|
+
var pattern = base === 16 ? /^[0-9A-F]+$/ : base === 2 ? /^[01]+$/ : /^[0-7]+$/;
|
|
56
|
+
if (!pattern.test(cleaned)) {
|
|
57
|
+
return errCollection[CommonErrors.Num];
|
|
58
|
+
}
|
|
59
|
+
var value = parseInt(cleaned, base);
|
|
60
|
+
if (isNaN(value)) {
|
|
61
|
+
return errCollection[CommonErrors.Num];
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
};
|
|
65
|
+
EngineeringBaseFormulas.prototype.resolveBaseArg = function (arg, base) {
|
|
66
|
+
var errCollection = this.parent.getErrorStrings();
|
|
67
|
+
var text = this.resolveTextArg(arg);
|
|
68
|
+
if (errCollection.indexOf(text) > -1) {
|
|
69
|
+
return text;
|
|
70
|
+
}
|
|
71
|
+
return this.parseBaseNumber(text, base);
|
|
72
|
+
};
|
|
73
|
+
EngineeringBaseFormulas.prototype.formatToBase = function (value, base, places) {
|
|
74
|
+
var errCollection = this.parent.getErrorStrings();
|
|
75
|
+
var num = Math.trunc(value);
|
|
76
|
+
var limits = {
|
|
77
|
+
2: { min: -512, max: 511, maxPlaces: 10 },
|
|
78
|
+
8: { min: -536870912, max: 536870911, maxPlaces: 10 },
|
|
79
|
+
10: { min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER, maxPlaces: 0 },
|
|
80
|
+
16: { min: -549755813888, max: 549755813887, maxPlaces: 10 }
|
|
81
|
+
};
|
|
82
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
83
|
+
var limit = limits[base];
|
|
84
|
+
if (num < limit.min || num > limit.max) {
|
|
85
|
+
return errCollection[CommonErrors.Num];
|
|
86
|
+
}
|
|
87
|
+
var negative = false;
|
|
88
|
+
if (num < 0) {
|
|
89
|
+
negative = true;
|
|
90
|
+
var width = places && places > 0 ? places : (base === 2 ? 10 : base === 8 ? 10 : 10);
|
|
91
|
+
num = (1 << width) + num;
|
|
92
|
+
}
|
|
93
|
+
var digits = num.toString(base).toUpperCase();
|
|
94
|
+
if (places !== undefined && places > 0) {
|
|
95
|
+
if (places > limit.maxPlaces) {
|
|
96
|
+
return errCollection[CommonErrors.Num];
|
|
97
|
+
}
|
|
98
|
+
while (digits.length < places) {
|
|
99
|
+
digits = '0' + digits;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return negative && base !== 10 ? digits : digits;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Converts a binary number to decimal.
|
|
106
|
+
*
|
|
107
|
+
* Excel: `BIN2DEC(...)`.
|
|
108
|
+
*
|
|
109
|
+
* @hidden
|
|
110
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
111
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* engine.computeFormula('=BIN2DEC(1)');
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
EngineeringBaseFormulas.prototype.ComputeBIN2DEC = function () {
|
|
119
|
+
var args = [];
|
|
120
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
121
|
+
args[_i] = arguments[_i];
|
|
122
|
+
}
|
|
123
|
+
if (isNullOrUndefined(args) || args.length !== 1) {
|
|
124
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
125
|
+
}
|
|
126
|
+
var val = this.resolveBaseArg(args[0], 2);
|
|
127
|
+
if (typeof val === 'string') {
|
|
128
|
+
return val;
|
|
129
|
+
}
|
|
130
|
+
var binary = this.resolveTextArg(args[0]).trim();
|
|
131
|
+
if (binary.length > 10) {
|
|
132
|
+
return this.parent.getErrorStrings()[CommonErrors.Num];
|
|
133
|
+
}
|
|
134
|
+
var num = val;
|
|
135
|
+
if (binary.length === 10 && binary.charAt(0) === '1') {
|
|
136
|
+
num = parseInt(binary, 2) - (1 << 10);
|
|
137
|
+
}
|
|
138
|
+
return num.toString();
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Converts a binary number to hexadecimal.
|
|
142
|
+
*
|
|
143
|
+
* Excel: `BIN2HEX(...)`.
|
|
144
|
+
*
|
|
145
|
+
* @hidden
|
|
146
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
147
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
148
|
+
*/
|
|
149
|
+
EngineeringBaseFormulas.prototype.ComputeBIN2HEX = function () {
|
|
150
|
+
var args = [];
|
|
151
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
152
|
+
args[_i] = arguments[_i];
|
|
153
|
+
}
|
|
154
|
+
return this.binTo(args, 16);
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Converts a binary number to octal.
|
|
158
|
+
*
|
|
159
|
+
* Excel: `BIN2OCT(...)`.
|
|
160
|
+
*
|
|
161
|
+
* @hidden
|
|
162
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
163
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
164
|
+
*/
|
|
165
|
+
EngineeringBaseFormulas.prototype.ComputeBIN2OCT = function () {
|
|
166
|
+
var args = [];
|
|
167
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
168
|
+
args[_i] = arguments[_i];
|
|
169
|
+
}
|
|
170
|
+
return this.binTo(args, 8);
|
|
171
|
+
};
|
|
172
|
+
EngineeringBaseFormulas.prototype.binTo = function (args, targetBase) {
|
|
173
|
+
var errCollection = this.parent.getErrorStrings();
|
|
174
|
+
if (isNullOrUndefined(args) || args.length < 1 || args.length > 2) {
|
|
175
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
176
|
+
}
|
|
177
|
+
var dec = this.ComputeBIN2DEC(args[0]);
|
|
178
|
+
if (typeof dec === 'string' && errCollection.indexOf(dec) > -1) {
|
|
179
|
+
return dec;
|
|
180
|
+
}
|
|
181
|
+
var places;
|
|
182
|
+
if (args.length === 2) {
|
|
183
|
+
var p = this.resolveNumberArg(args[1]);
|
|
184
|
+
if (typeof p === 'string') {
|
|
185
|
+
return p;
|
|
186
|
+
}
|
|
187
|
+
places = Math.floor(p);
|
|
188
|
+
}
|
|
189
|
+
return this.formatToBase(parseInt(dec.toString(), 10), targetBase, places);
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Converts a decimal number to binary.
|
|
193
|
+
*
|
|
194
|
+
* Excel: `DEC2BIN(...)`.
|
|
195
|
+
*
|
|
196
|
+
* @hidden
|
|
197
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
198
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
199
|
+
*/
|
|
200
|
+
EngineeringBaseFormulas.prototype.ComputeDEC2BIN = function () {
|
|
201
|
+
var args = [];
|
|
202
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
203
|
+
args[_i] = arguments[_i];
|
|
204
|
+
}
|
|
205
|
+
return this.decTo(args, 2);
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Converts a decimal number to hexadecimal.
|
|
209
|
+
*
|
|
210
|
+
* Excel: `DEC2HEX(...)`.
|
|
211
|
+
*
|
|
212
|
+
* @hidden
|
|
213
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
214
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
215
|
+
*/
|
|
216
|
+
EngineeringBaseFormulas.prototype.ComputeDEC2HEX = function () {
|
|
217
|
+
var args = [];
|
|
218
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
219
|
+
args[_i] = arguments[_i];
|
|
220
|
+
}
|
|
221
|
+
return this.decTo(args, 16);
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Converts a decimal number to octal.
|
|
225
|
+
*
|
|
226
|
+
* Excel: `DEC2OCT(...)`.
|
|
227
|
+
*
|
|
228
|
+
* @hidden
|
|
229
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
230
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
231
|
+
*/
|
|
232
|
+
EngineeringBaseFormulas.prototype.ComputeDEC2OCT = function () {
|
|
233
|
+
var args = [];
|
|
234
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
235
|
+
args[_i] = arguments[_i];
|
|
236
|
+
}
|
|
237
|
+
return this.decTo(args, 8);
|
|
238
|
+
};
|
|
239
|
+
EngineeringBaseFormulas.prototype.decTo = function (args, targetBase) {
|
|
240
|
+
if (isNullOrUndefined(args) || args.length < 1 || args.length > 2) {
|
|
241
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
242
|
+
}
|
|
243
|
+
var num = this.resolveNumberArg(args[0]);
|
|
244
|
+
if (typeof num === 'string') {
|
|
245
|
+
return num;
|
|
246
|
+
}
|
|
247
|
+
var places;
|
|
248
|
+
if (args.length === 2) {
|
|
249
|
+
var p = this.resolveNumberArg(args[1]);
|
|
250
|
+
if (typeof p === 'string') {
|
|
251
|
+
return p;
|
|
252
|
+
}
|
|
253
|
+
places = Math.floor(p);
|
|
254
|
+
}
|
|
255
|
+
return this.formatToBase(Math.trunc(num), targetBase, places);
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Converts a hexadecimal number to decimal.
|
|
259
|
+
*
|
|
260
|
+
* Excel: `HEX2DEC(...)`.
|
|
261
|
+
*
|
|
262
|
+
* @hidden
|
|
263
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
264
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
265
|
+
*/
|
|
266
|
+
EngineeringBaseFormulas.prototype.ComputeHEX2DEC = function () {
|
|
267
|
+
var args = [];
|
|
268
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
269
|
+
args[_i] = arguments[_i];
|
|
270
|
+
}
|
|
271
|
+
if (isNullOrUndefined(args) || args.length !== 1) {
|
|
272
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
273
|
+
}
|
|
274
|
+
var text = this.resolveTextArg(args[0]).trim().toUpperCase();
|
|
275
|
+
var val = this.parseBaseNumber(text, 16);
|
|
276
|
+
if (typeof val === 'string') {
|
|
277
|
+
return val;
|
|
278
|
+
}
|
|
279
|
+
if (text.length > 10) {
|
|
280
|
+
return this.parent.getErrorStrings()[CommonErrors.Num];
|
|
281
|
+
}
|
|
282
|
+
var num = val;
|
|
283
|
+
if (text.length === 10 && parseInt(text.charAt(0), 16) >= 8) {
|
|
284
|
+
num = parseInt(text, 16) - (1 << 40);
|
|
285
|
+
}
|
|
286
|
+
return num.toString();
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Converts a hexadecimal number to binary.
|
|
290
|
+
*
|
|
291
|
+
* Excel: `HEX2BIN(...)`.
|
|
292
|
+
*
|
|
293
|
+
* @hidden
|
|
294
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
295
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
296
|
+
*/
|
|
297
|
+
EngineeringBaseFormulas.prototype.ComputeHEX2BIN = function () {
|
|
298
|
+
var args = [];
|
|
299
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
300
|
+
args[_i] = arguments[_i];
|
|
301
|
+
}
|
|
302
|
+
return this.hexOctTo(args, 2, this.ComputeHEX2DEC.bind(this));
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Converts a hexadecimal number to octal.
|
|
306
|
+
*
|
|
307
|
+
* Excel: `HEX2OCT(...)`.
|
|
308
|
+
*
|
|
309
|
+
* @hidden
|
|
310
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
311
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
312
|
+
*/
|
|
313
|
+
EngineeringBaseFormulas.prototype.ComputeHEX2OCT = function () {
|
|
314
|
+
var args = [];
|
|
315
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
316
|
+
args[_i] = arguments[_i];
|
|
317
|
+
}
|
|
318
|
+
return this.hexOctTo(args, 8, this.ComputeHEX2DEC.bind(this));
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* Converts an octal number to decimal.
|
|
322
|
+
*
|
|
323
|
+
* Excel: `OCT2DEC(...)`.
|
|
324
|
+
*
|
|
325
|
+
* @hidden
|
|
326
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
327
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
328
|
+
*/
|
|
329
|
+
EngineeringBaseFormulas.prototype.ComputeOCT2DEC = function () {
|
|
330
|
+
var args = [];
|
|
331
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
332
|
+
args[_i] = arguments[_i];
|
|
333
|
+
}
|
|
334
|
+
if (isNullOrUndefined(args) || args.length !== 1) {
|
|
335
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
336
|
+
}
|
|
337
|
+
var text = this.resolveTextArg(args[0]).trim();
|
|
338
|
+
var val = this.parseBaseNumber(text, 8);
|
|
339
|
+
if (typeof val === 'string') {
|
|
340
|
+
return val;
|
|
341
|
+
}
|
|
342
|
+
if (text.length > 10) {
|
|
343
|
+
return this.parent.getErrorStrings()[CommonErrors.Num];
|
|
344
|
+
}
|
|
345
|
+
var num = val;
|
|
346
|
+
if (text.length === 10 && text.charAt(0) >= '4') {
|
|
347
|
+
num = parseInt(text, 8) - (1 << 30);
|
|
348
|
+
}
|
|
349
|
+
return num.toString();
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* Converts an octal number to binary.
|
|
353
|
+
*
|
|
354
|
+
* Excel: `OCT2BIN(...)`.
|
|
355
|
+
*
|
|
356
|
+
* @hidden
|
|
357
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
358
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
359
|
+
*/
|
|
360
|
+
EngineeringBaseFormulas.prototype.ComputeOCT2BIN = function () {
|
|
361
|
+
var args = [];
|
|
362
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
363
|
+
args[_i] = arguments[_i];
|
|
364
|
+
}
|
|
365
|
+
return this.hexOctTo(args, 2, this.ComputeOCT2DEC.bind(this));
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* Converts an octal number to hexadecimal.
|
|
369
|
+
*
|
|
370
|
+
* Excel: `OCT2HEX(...)`.
|
|
371
|
+
*
|
|
372
|
+
* @hidden
|
|
373
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
374
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
375
|
+
*/
|
|
376
|
+
EngineeringBaseFormulas.prototype.ComputeOCT2HEX = function () {
|
|
377
|
+
var args = [];
|
|
378
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
379
|
+
args[_i] = arguments[_i];
|
|
380
|
+
}
|
|
381
|
+
return this.hexOctTo(args, 16, this.ComputeOCT2DEC.bind(this));
|
|
382
|
+
};
|
|
383
|
+
EngineeringBaseFormulas.prototype.hexOctTo = function (args, targetBase, toDec) {
|
|
384
|
+
var errCollection = this.parent.getErrorStrings();
|
|
385
|
+
if (isNullOrUndefined(args) || args.length < 1 || args.length > 2) {
|
|
386
|
+
return this.parent.formulaErrorStrings[FormulasErrorsStrings.WrongNumberArguments];
|
|
387
|
+
}
|
|
388
|
+
var dec = toDec(args[0]);
|
|
389
|
+
if (typeof dec === 'string' && errCollection.indexOf(dec) > -1) {
|
|
390
|
+
return dec;
|
|
391
|
+
}
|
|
392
|
+
var places;
|
|
393
|
+
if (args.length === 2) {
|
|
394
|
+
var p = this.resolveNumberArg(args[1]);
|
|
395
|
+
if (typeof p === 'string') {
|
|
396
|
+
return p;
|
|
397
|
+
}
|
|
398
|
+
places = Math.floor(p);
|
|
399
|
+
}
|
|
400
|
+
return this.formatToBase(parseInt(dec.toString(), 10), targetBase, places);
|
|
401
|
+
};
|
|
402
|
+
return EngineeringBaseFormulas;
|
|
403
|
+
}(FormulaModuleBase));
|
|
404
|
+
export { EngineeringBaseFormulas };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { IBasicFormula } from '../common/index';
|
|
2
|
+
import { FormulaOwner } from './formula-owner';
|
|
3
|
+
import { FormulaModuleBase } from './formula-module-base';
|
|
4
|
+
/**
|
|
5
|
+
* Bessel function family (J, Y, I, K) for oscillatory and decaying physical models.
|
|
6
|
+
*
|
|
7
|
+
* Registered functions: BESSELI, BESSELJ, BESSELK, BESSELY.
|
|
8
|
+
*
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export declare class EngineeringBesselFormulas 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 besselArgs;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the modified Bessel function In(x).
|
|
22
|
+
*
|
|
23
|
+
* Excel: `BESSELI(...)`.
|
|
24
|
+
*
|
|
25
|
+
* @hidden
|
|
26
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
27
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* engine.computeFormula('=BESSELI(1)');
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
ComputeBESSELI(...args: string[]): string | number;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the Bessel function Jn(x).
|
|
37
|
+
*
|
|
38
|
+
* Excel: `BESSELJ(...)`.
|
|
39
|
+
*
|
|
40
|
+
* @hidden
|
|
41
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
42
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
43
|
+
*/
|
|
44
|
+
ComputeBESSELJ(...args: string[]): string | number;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the modified Bessel function Kn(x).
|
|
47
|
+
*
|
|
48
|
+
* Excel: `BESSELK(...)`.
|
|
49
|
+
*
|
|
50
|
+
* @hidden
|
|
51
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
52
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
53
|
+
*/
|
|
54
|
+
ComputeBESSELK(...args: string[]): string | number;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the Bessel function Yn(x).
|
|
57
|
+
*
|
|
58
|
+
* Excel: `BESSELY(...)`.
|
|
59
|
+
*
|
|
60
|
+
* @hidden
|
|
61
|
+
* @param {string[]} args - Formula argument tokens from the Calculate engine.
|
|
62
|
+
* @returns {string | number} - Computed Excel-compatible numeric or text result, or an error token such as `#VALUE!`, `#NUM!`, `#N/A`.
|
|
63
|
+
*/
|
|
64
|
+
ComputeBESSELY(...args: string[]): string | number;
|
|
65
|
+
}
|