mathjs 12.2.1 → 12.3.1
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +27 -0
- package/NOTICE +1 -1
- package/README.md +4 -3
- package/bin/cli.js +1 -1
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +3 -3
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/entry/configReadonly.js +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesHelpClass.generated.js +2 -2
- package/lib/cjs/entry/dependenciesNumber/dependenciesHelpClass.generated.js +2 -2
- package/lib/cjs/entry/impureFunctionsAny.generated.js +14 -14
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +1 -1
- package/lib/cjs/entry/pureFunctionsAny.generated.js +11 -11
- package/lib/cjs/expression/Help.js +21 -4
- package/lib/cjs/expression/node/AccessorNode.js +4 -5
- package/lib/cjs/expression/node/ArrayNode.js +4 -5
- package/lib/cjs/expression/node/AssignmentNode.js +4 -5
- package/lib/cjs/expression/node/BlockNode.js +4 -5
- package/lib/cjs/expression/node/ConditionalNode.js +4 -5
- package/lib/cjs/expression/node/ConstantNode.js +4 -5
- package/lib/cjs/expression/node/FunctionAssignmentNode.js +4 -5
- package/lib/cjs/expression/node/FunctionNode.js +5 -6
- package/lib/cjs/expression/node/IndexNode.js +4 -5
- package/lib/cjs/expression/node/ObjectNode.js +4 -5
- package/lib/cjs/expression/node/OperatorNode.js +4 -5
- package/lib/cjs/expression/node/ParenthesisNode.js +4 -5
- package/lib/cjs/expression/node/RangeNode.js +4 -5
- package/lib/cjs/expression/node/RelationalNode.js +4 -5
- package/lib/cjs/expression/node/SymbolNode.js +4 -5
- package/lib/cjs/function/string/bin.js +3 -3
- package/lib/cjs/function/string/format.js +3 -3
- package/lib/cjs/function/string/hex.js +3 -3
- package/lib/cjs/function/string/oct.js +3 -3
- package/lib/cjs/header.js +3 -3
- package/lib/cjs/type/unit/Unit.js +86 -2
- package/lib/cjs/type/unit/physicalConstants.js +1 -1
- package/lib/cjs/utils/bignumber/formatter.js +17 -27
- package/lib/cjs/utils/number.js +75 -33
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/configReadonly.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesHelpClass.generated.js +2 -2
- package/lib/esm/entry/dependenciesNumber/dependenciesHelpClass.generated.js +2 -2
- package/lib/esm/entry/impureFunctionsAny.generated.js +16 -16
- package/lib/esm/entry/impureFunctionsNumber.generated.js +1 -1
- package/lib/esm/entry/pureFunctionsAny.generated.js +12 -12
- package/lib/esm/expression/Help.js +21 -4
- package/lib/esm/function/string/bin.js +3 -3
- package/lib/esm/function/string/format.js +3 -3
- package/lib/esm/function/string/hex.js +3 -3
- package/lib/esm/function/string/oct.js +3 -3
- package/lib/esm/header.js +1 -1
- package/lib/esm/type/unit/Unit.js +86 -2
- package/lib/esm/type/unit/physicalConstants.js +1 -1
- package/lib/esm/utils/bignumber/formatter.js +19 -28
- package/lib/esm/utils/number.js +76 -34
- package/lib/esm/version.js +1 -1
- package/package.json +14 -14
- package/types/index.d.ts +30 -18
@@ -731,7 +731,7 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
731
731
|
Unit.prototype.abs = function () {
|
732
732
|
var ret = this.clone();
|
733
733
|
if (ret.value !== null) {
|
734
|
-
if (ret._isDerived() || ret.units[0].unit.offset === 0) {
|
734
|
+
if (ret._isDerived() || ret.units.length === 0 || ret.units[0].unit.offset === 0) {
|
735
735
|
ret.value = abs(ret.value);
|
736
736
|
} else {
|
737
737
|
// To give the correct, but unexpected, results for units with an offset.
|
@@ -774,7 +774,7 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
774
774
|
if (other.value !== null) {
|
775
775
|
throw new Error('Cannot convert to a unit with a value');
|
776
776
|
}
|
777
|
-
if (this.value === null || this._isDerived() || this.units[0].unit.offset === other.units[0].unit.offset) {
|
777
|
+
if (this.value === null || this._isDerived() || this.units.length === 0 || other.units.length === 0 || this.units[0].unit.offset === other.units[0].unit.offset) {
|
778
778
|
other.value = clone(value);
|
779
779
|
} else {
|
780
780
|
/* Need to adjust value by difference in offset to convert */
|
@@ -962,6 +962,10 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
962
962
|
ret.units = proposedUnitList;
|
963
963
|
ret.fixPrefix = true;
|
964
964
|
ret.skipAutomaticSimplification = true;
|
965
|
+
if (this.value !== null) {
|
966
|
+
ret.value = null;
|
967
|
+
return this.to(ret);
|
968
|
+
}
|
965
969
|
return ret;
|
966
970
|
};
|
967
971
|
|
@@ -1242,6 +1246,16 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
1242
1246
|
value: 1e24,
|
1243
1247
|
scientific: true
|
1244
1248
|
},
|
1249
|
+
R: {
|
1250
|
+
name: 'R',
|
1251
|
+
value: 1e27,
|
1252
|
+
scientific: true
|
1253
|
+
},
|
1254
|
+
Q: {
|
1255
|
+
name: 'Q',
|
1256
|
+
value: 1e30,
|
1257
|
+
scientific: true
|
1258
|
+
},
|
1245
1259
|
d: {
|
1246
1260
|
name: 'd',
|
1247
1261
|
value: 1e-1,
|
@@ -1291,6 +1305,16 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
1291
1305
|
name: 'y',
|
1292
1306
|
value: 1e-24,
|
1293
1307
|
scientific: true
|
1308
|
+
},
|
1309
|
+
r: {
|
1310
|
+
name: 'r',
|
1311
|
+
value: 1e-27,
|
1312
|
+
scientific: true
|
1313
|
+
},
|
1314
|
+
q: {
|
1315
|
+
name: 'q',
|
1316
|
+
value: 1e-30,
|
1317
|
+
scientific: true
|
1294
1318
|
}
|
1295
1319
|
},
|
1296
1320
|
LONG: {
|
@@ -1349,6 +1373,16 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
1349
1373
|
value: 1e24,
|
1350
1374
|
scientific: true
|
1351
1375
|
},
|
1376
|
+
ronna: {
|
1377
|
+
name: 'ronna',
|
1378
|
+
value: 1e27,
|
1379
|
+
scientific: true
|
1380
|
+
},
|
1381
|
+
quetta: {
|
1382
|
+
name: 'quetta',
|
1383
|
+
value: 1e30,
|
1384
|
+
scientific: true
|
1385
|
+
},
|
1352
1386
|
deci: {
|
1353
1387
|
name: 'deci',
|
1354
1388
|
value: 1e-1,
|
@@ -1398,6 +1432,16 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
1398
1432
|
name: 'yocto',
|
1399
1433
|
value: 1e-24,
|
1400
1434
|
scientific: true
|
1435
|
+
},
|
1436
|
+
ronto: {
|
1437
|
+
name: 'ronto',
|
1438
|
+
value: 1e-27,
|
1439
|
+
scientific: true
|
1440
|
+
},
|
1441
|
+
quecto: {
|
1442
|
+
name: 'quecto',
|
1443
|
+
value: 1e-30,
|
1444
|
+
scientific: true
|
1401
1445
|
}
|
1402
1446
|
},
|
1403
1447
|
SQUARED: {
|
@@ -1456,6 +1500,16 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
1456
1500
|
value: 1e48,
|
1457
1501
|
scientific: true
|
1458
1502
|
},
|
1503
|
+
R: {
|
1504
|
+
name: 'R',
|
1505
|
+
value: 1e54,
|
1506
|
+
scientific: true
|
1507
|
+
},
|
1508
|
+
Q: {
|
1509
|
+
name: 'Q',
|
1510
|
+
value: 1e60,
|
1511
|
+
scientific: true
|
1512
|
+
},
|
1459
1513
|
d: {
|
1460
1514
|
name: 'd',
|
1461
1515
|
value: 1e-2,
|
@@ -1505,6 +1559,16 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
1505
1559
|
name: 'y',
|
1506
1560
|
value: 1e-48,
|
1507
1561
|
scientific: true
|
1562
|
+
},
|
1563
|
+
r: {
|
1564
|
+
name: 'r',
|
1565
|
+
value: 1e-54,
|
1566
|
+
scientific: true
|
1567
|
+
},
|
1568
|
+
q: {
|
1569
|
+
name: 'q',
|
1570
|
+
value: 1e-60,
|
1571
|
+
scientific: true
|
1508
1572
|
}
|
1509
1573
|
},
|
1510
1574
|
CUBIC: {
|
@@ -1563,6 +1627,16 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
1563
1627
|
value: 1e72,
|
1564
1628
|
scientific: true
|
1565
1629
|
},
|
1630
|
+
R: {
|
1631
|
+
name: 'R',
|
1632
|
+
value: 1e81,
|
1633
|
+
scientific: true
|
1634
|
+
},
|
1635
|
+
Q: {
|
1636
|
+
name: 'Q',
|
1637
|
+
value: 1e90,
|
1638
|
+
scientific: true
|
1639
|
+
},
|
1566
1640
|
d: {
|
1567
1641
|
name: 'd',
|
1568
1642
|
value: 1e-3,
|
@@ -1612,6 +1686,16 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
1612
1686
|
name: 'y',
|
1613
1687
|
value: 1e-72,
|
1614
1688
|
scientific: true
|
1689
|
+
},
|
1690
|
+
r: {
|
1691
|
+
name: 'r',
|
1692
|
+
value: 1e-81,
|
1693
|
+
scientific: true
|
1694
|
+
},
|
1695
|
+
q: {
|
1696
|
+
name: 'q',
|
1697
|
+
value: 1e-90,
|
1698
|
+
scientific: true
|
1615
1699
|
}
|
1616
1700
|
},
|
1617
1701
|
BINARY_SHORT_SI: {
|
@@ -44,7 +44,7 @@ export var createAvogadro = /* #__PURE__ */unitFactory('avogadro', '6.02214076e2
|
|
44
44
|
export var createBoltzmann = /* #__PURE__ */unitFactory('boltzmann', '1.380649e-23', 'J K^-1');
|
45
45
|
export var createFaraday = /* #__PURE__ */unitFactory('faraday', '96485.33212331001', 'C mol^-1');
|
46
46
|
export var createFirstRadiation = /* #__PURE__ */unitFactory('firstRadiation', '3.7417718521927573e-16', 'W m^2');
|
47
|
-
//
|
47
|
+
// TODO spectralRadiance = 1.1910429723971881e-16 W m^2 sr^-1
|
48
48
|
export var createLoschmidt = /* #__PURE__ */unitFactory('loschmidt', '2.686780111798444e25', 'm^-3');
|
49
49
|
export var createGasConstant = /* #__PURE__ */unitFactory('gasConstant', '8.31446261815324', 'J K^-1 mol^-1');
|
50
50
|
export var createMolarPlanckConstant = /* #__PURE__ */unitFactory('molarPlanckConstant', '3.990312712893431e-10', 'J s mol^-1');
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { isBigNumber, isNumber } from '../is.js';
|
2
|
+
import { isInteger, normalizeFormatOptions } from '../number.js';
|
2
3
|
|
3
4
|
/**
|
4
5
|
* Formats a BigNumber in a given base
|
@@ -119,7 +120,7 @@ function formatBigNumberToBase(n, base, size) {
|
|
119
120
|
* format(12400, {notation: 'engineering'}) // returns '12.400e+3'
|
120
121
|
*
|
121
122
|
* @param {BigNumber} value
|
122
|
-
* @param {Object | Function | number} [options]
|
123
|
+
* @param {Object | Function | number | BigNumber} [options]
|
123
124
|
* @return {string} str The formatted value
|
124
125
|
*/
|
125
126
|
export function format(value, options) {
|
@@ -132,30 +133,11 @@ export function format(value, options) {
|
|
132
133
|
if (!value.isFinite()) {
|
133
134
|
return value.isNaN() ? 'NaN' : value.gt(0) ? 'Infinity' : '-Infinity';
|
134
135
|
}
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
if (options !== undefined) {
|
141
|
-
// determine notation from options
|
142
|
-
if (options.notation) {
|
143
|
-
notation = options.notation;
|
144
|
-
}
|
145
|
-
|
146
|
-
// determine precision from options
|
147
|
-
if (typeof options === 'number') {
|
148
|
-
precision = options;
|
149
|
-
} else if (options.precision !== undefined) {
|
150
|
-
precision = options.precision;
|
151
|
-
}
|
152
|
-
if (options.wordSize) {
|
153
|
-
wordSize = options.wordSize;
|
154
|
-
if (typeof wordSize !== 'number') {
|
155
|
-
throw new Error('Option "wordSize" must be a number');
|
156
|
-
}
|
157
|
-
}
|
158
|
-
}
|
136
|
+
var {
|
137
|
+
notation,
|
138
|
+
precision,
|
139
|
+
wordSize
|
140
|
+
} = normalizeFormatOptions(options);
|
159
141
|
|
160
142
|
// handle the various notations
|
161
143
|
switch (notation) {
|
@@ -175,8 +157,8 @@ export function format(value, options) {
|
|
175
157
|
{
|
176
158
|
// determine lower and upper bound for exponential notation.
|
177
159
|
// TODO: implement support for upper and lower to be BigNumbers themselves
|
178
|
-
var lowerExp = options
|
179
|
-
var upperExp = options
|
160
|
+
var lowerExp = _toNumberOrDefault(options === null || options === void 0 ? void 0 : options.lowerExp, -3);
|
161
|
+
var upperExp = _toNumberOrDefault(options === null || options === void 0 ? void 0 : options.upperExp, 5);
|
180
162
|
|
181
163
|
// handle special case zero
|
182
164
|
if (value.isZero()) return '0';
|
@@ -249,4 +231,13 @@ export function toExponential(value, precision) {
|
|
249
231
|
*/
|
250
232
|
export function toFixed(value, precision) {
|
251
233
|
return value.toFixed(precision);
|
234
|
+
}
|
235
|
+
function _toNumberOrDefault(value, defaultValue) {
|
236
|
+
if (isNumber(value)) {
|
237
|
+
return value;
|
238
|
+
} else if (isBigNumber(value)) {
|
239
|
+
return value.toNumber();
|
240
|
+
} else {
|
241
|
+
return defaultValue;
|
242
|
+
}
|
252
243
|
}
|
package/lib/esm/utils/number.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { isNumber } from './is.js';
|
1
|
+
import { isBigNumber, isNumber, isObject } from './is.js';
|
2
2
|
|
3
3
|
/**
|
4
4
|
* @typedef {{sign: '+' | '-' | '', coefficients: number[], exponent: number}} SplitValue
|
@@ -21,7 +21,7 @@ export function isInteger(value) {
|
|
21
21
|
* @param {number} x
|
22
22
|
* @returns {number}
|
23
23
|
*/
|
24
|
-
export var sign =
|
24
|
+
export var sign = Math.sign || function (x) {
|
25
25
|
if (x > 0) {
|
26
26
|
return 1;
|
27
27
|
} else if (x < 0) {
|
@@ -36,7 +36,7 @@ export var sign = /* #__PURE__ */Math.sign || function (x) {
|
|
36
36
|
* @param {number} x
|
37
37
|
* @returns {number}
|
38
38
|
*/
|
39
|
-
export var log2 =
|
39
|
+
export var log2 = Math.log2 || function log2(x) {
|
40
40
|
return Math.log(x) / Math.LN2;
|
41
41
|
};
|
42
42
|
|
@@ -45,7 +45,7 @@ export var log2 = /* #__PURE__ */Math.log2 || function log2(x) {
|
|
45
45
|
* @param {number} x
|
46
46
|
* @returns {number}
|
47
47
|
*/
|
48
|
-
export var log10 =
|
48
|
+
export var log10 = Math.log10 || function log10(x) {
|
49
49
|
return Math.log(x) / Math.LN10;
|
50
50
|
};
|
51
51
|
|
@@ -54,7 +54,7 @@ export var log10 = /* #__PURE__ */Math.log10 || function log10(x) {
|
|
54
54
|
* @param {number} x
|
55
55
|
* @returns {number}
|
56
56
|
*/
|
57
|
-
export var log1p =
|
57
|
+
export var log1p = Math.log1p || function (x) {
|
58
58
|
return Math.log(x + 1);
|
59
59
|
};
|
60
60
|
|
@@ -67,7 +67,7 @@ export var log1p = /* #__PURE__ */Math.log1p || function (x) {
|
|
67
67
|
* @param {number} x
|
68
68
|
* @returns {number} Returns the cubic root of x
|
69
69
|
*/
|
70
|
-
export var cbrt =
|
70
|
+
export var cbrt = Math.cbrt || function cbrt(x) {
|
71
71
|
if (x === 0) {
|
72
72
|
return x;
|
73
73
|
}
|
@@ -91,7 +91,7 @@ export var cbrt = /* #__PURE__ */Math.cbrt || function cbrt(x) {
|
|
91
91
|
* @param {number} x
|
92
92
|
* @return {number} res
|
93
93
|
*/
|
94
|
-
export var expm1 =
|
94
|
+
export var expm1 = Math.expm1 || function expm1(x) {
|
95
95
|
return x >= 2e-4 || x <= -2e-4 ? Math.exp(x) - 1 : x + x * x / 2 + x * x * x / 6;
|
96
96
|
};
|
97
97
|
|
@@ -234,30 +234,11 @@ export function format(value, options) {
|
|
234
234
|
} else if (isNaN(value)) {
|
235
235
|
return 'NaN';
|
236
236
|
}
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
if (options) {
|
243
|
-
// determine notation from options
|
244
|
-
if (options.notation) {
|
245
|
-
notation = options.notation;
|
246
|
-
}
|
247
|
-
|
248
|
-
// determine precision from options
|
249
|
-
if (isNumber(options)) {
|
250
|
-
precision = options;
|
251
|
-
} else if (isNumber(options.precision)) {
|
252
|
-
precision = options.precision;
|
253
|
-
}
|
254
|
-
if (options.wordSize) {
|
255
|
-
wordSize = options.wordSize;
|
256
|
-
if (typeof wordSize !== 'number') {
|
257
|
-
throw new Error('Option "wordSize" must be a number');
|
258
|
-
}
|
259
|
-
}
|
260
|
-
}
|
237
|
+
var {
|
238
|
+
notation,
|
239
|
+
precision,
|
240
|
+
wordSize
|
241
|
+
} = normalizeFormatOptions(options);
|
261
242
|
|
262
243
|
// handle the various notations
|
263
244
|
switch (notation) {
|
@@ -275,7 +256,7 @@ export function format(value, options) {
|
|
275
256
|
return formatNumberToBase(value, 16, wordSize);
|
276
257
|
case 'auto':
|
277
258
|
// remove trailing zeros after the decimal point
|
278
|
-
return toPrecision(value, precision, options
|
259
|
+
return toPrecision(value, precision, options).replace(/((\.\d*?)(0+))($|e)/, function () {
|
279
260
|
var digits = arguments[2];
|
280
261
|
var e = arguments[4];
|
281
262
|
return digits !== '.' ? digits + e : e;
|
@@ -285,6 +266,49 @@ export function format(value, options) {
|
|
285
266
|
}
|
286
267
|
}
|
287
268
|
|
269
|
+
/**
|
270
|
+
* Normalize format options into an object:
|
271
|
+
* {
|
272
|
+
* notation: string,
|
273
|
+
* precision: number | undefined,
|
274
|
+
* wordSize: number | undefined
|
275
|
+
* }
|
276
|
+
*/
|
277
|
+
export function normalizeFormatOptions(options) {
|
278
|
+
// default values for options
|
279
|
+
var notation = 'auto';
|
280
|
+
var precision;
|
281
|
+
var wordSize;
|
282
|
+
if (options !== undefined) {
|
283
|
+
if (isNumber(options)) {
|
284
|
+
precision = options;
|
285
|
+
} else if (isBigNumber(options)) {
|
286
|
+
precision = options.toNumber();
|
287
|
+
} else if (isObject(options)) {
|
288
|
+
if (options.precision !== undefined) {
|
289
|
+
precision = _toNumberOrThrow(options.precision, () => {
|
290
|
+
throw new Error('Option "precision" must be a number or BigNumber');
|
291
|
+
});
|
292
|
+
}
|
293
|
+
if (options.wordSize !== undefined) {
|
294
|
+
wordSize = _toNumberOrThrow(options.wordSize, () => {
|
295
|
+
throw new Error('Option "wordSize" must be a number or BigNumber');
|
296
|
+
});
|
297
|
+
}
|
298
|
+
if (options.notation) {
|
299
|
+
notation = options.notation;
|
300
|
+
}
|
301
|
+
} else {
|
302
|
+
throw new Error('Unsupported type of options, number, BigNumber, or object expected');
|
303
|
+
}
|
304
|
+
}
|
305
|
+
return {
|
306
|
+
notation,
|
307
|
+
precision,
|
308
|
+
wordSize
|
309
|
+
};
|
310
|
+
}
|
311
|
+
|
288
312
|
/**
|
289
313
|
* Split a number into sign, coefficients, and exponent
|
290
314
|
* @param {number | string} value
|
@@ -448,8 +472,8 @@ export function toPrecision(value, precision, options) {
|
|
448
472
|
}
|
449
473
|
|
450
474
|
// determine lower and upper bound for exponential notation.
|
451
|
-
var lowerExp = options
|
452
|
-
var upperExp = options
|
475
|
+
var lowerExp = _toNumberOrDefault(options === null || options === void 0 ? void 0 : options.lowerExp, -3);
|
476
|
+
var upperExp = _toNumberOrDefault(options === null || options === void 0 ? void 0 : options.upperExp, 5);
|
453
477
|
var split = splitNumber(value);
|
454
478
|
var rounded = precision ? roundDigits(split, precision) : split;
|
455
479
|
if (rounded.exponent < lowerExp || rounded.exponent >= upperExp) {
|
@@ -654,4 +678,22 @@ export function copysign(x, y) {
|
|
654
678
|
var signx = x > 0 ? true : x < 0 ? false : 1 / x === Infinity;
|
655
679
|
var signy = y > 0 ? true : y < 0 ? false : 1 / y === Infinity;
|
656
680
|
return signx ^ signy ? -x : x;
|
681
|
+
}
|
682
|
+
function _toNumberOrThrow(value, onError) {
|
683
|
+
if (isNumber(value)) {
|
684
|
+
return value;
|
685
|
+
} else if (isBigNumber(value)) {
|
686
|
+
return value.toNumber();
|
687
|
+
} else {
|
688
|
+
onError();
|
689
|
+
}
|
690
|
+
}
|
691
|
+
function _toNumberOrDefault(value, defaultValue) {
|
692
|
+
if (isNumber(value)) {
|
693
|
+
return value;
|
694
|
+
} else if (isBigNumber(value)) {
|
695
|
+
return value.toNumber();
|
696
|
+
} else {
|
697
|
+
return defaultValue;
|
698
|
+
}
|
657
699
|
}
|
package/lib/esm/version.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mathjs",
|
3
|
-
"version": "12.
|
3
|
+
"version": "12.3.1",
|
4
4
|
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
|
5
5
|
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
|
6
6
|
"homepage": "https://mathjs.org",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"unit"
|
26
26
|
],
|
27
27
|
"dependencies": {
|
28
|
-
"@babel/runtime": "^7.23.
|
28
|
+
"@babel/runtime": "^7.23.9",
|
29
29
|
"complex.js": "^2.1.1",
|
30
30
|
"decimal.js": "^10.4.3",
|
31
31
|
"escape-latex": "^1.2.0",
|
@@ -36,21 +36,21 @@
|
|
36
36
|
"typed-function": "^4.1.1"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
|
-
"@babel/core": "7.23.
|
39
|
+
"@babel/core": "7.23.9",
|
40
40
|
"@babel/plugin-transform-object-assign": "7.23.3",
|
41
|
-
"@babel/plugin-transform-runtime": "7.23.
|
42
|
-
"@babel/preset-env": "7.23.
|
43
|
-
"@babel/register": "7.
|
41
|
+
"@babel/plugin-transform-runtime": "7.23.9",
|
42
|
+
"@babel/preset-env": "7.23.9",
|
43
|
+
"@babel/register": "7.23.7",
|
44
44
|
"@types/assert": "1.5.10",
|
45
45
|
"@types/mocha": "10.0.6",
|
46
|
-
"@typescript-eslint/eslint-plugin": "6.
|
47
|
-
"@typescript-eslint/parser": "6.
|
46
|
+
"@typescript-eslint/eslint-plugin": "6.20.0",
|
47
|
+
"@typescript-eslint/parser": "6.20.0",
|
48
48
|
"assert": "2.1.0",
|
49
49
|
"babel-loader": "9.1.3",
|
50
50
|
"benchmark": "2.1.4",
|
51
|
-
"c8": "
|
51
|
+
"c8": "9.1.0",
|
52
52
|
"codecov": "3.8.3",
|
53
|
-
"core-js": "3.
|
53
|
+
"core-js": "3.35.1",
|
54
54
|
"del": "6.1.1",
|
55
55
|
"dtslint": "4.2.1",
|
56
56
|
"eslint": "8.56.0",
|
@@ -58,8 +58,8 @@
|
|
58
58
|
"eslint-config-standard": "17.1.0",
|
59
59
|
"eslint-plugin-import": "2.29.1",
|
60
60
|
"eslint-plugin-mocha": "10.2.0",
|
61
|
-
"eslint-plugin-n": "16.
|
62
|
-
"eslint-plugin-prettier": "5.1.
|
61
|
+
"eslint-plugin-n": "16.6.2",
|
62
|
+
"eslint-plugin-prettier": "5.1.3",
|
63
63
|
"eslint-plugin-promise": "6.1.1",
|
64
64
|
"expect-type": "0.17.3",
|
65
65
|
"expr-eval": "2.0.2",
|
@@ -85,12 +85,12 @@
|
|
85
85
|
"ndarray-pack": "1.2.1",
|
86
86
|
"numericjs": "1.2.6",
|
87
87
|
"pad-right": "0.2.2",
|
88
|
-
"prettier": "3.
|
88
|
+
"prettier": "3.2.4",
|
89
89
|
"process": "0.11.10",
|
90
90
|
"sylvester": "0.0.21",
|
91
91
|
"ts-node": "10.9.2",
|
92
92
|
"typescript": "5.3.3",
|
93
|
-
"webpack": "5.
|
93
|
+
"webpack": "5.90.0",
|
94
94
|
"zeros": "1.0.0"
|
95
95
|
},
|
96
96
|
"type": "module",
|
package/types/index.d.ts
CHANGED
@@ -183,11 +183,11 @@ export interface ArrayNode<TItems extends MathNode[] = MathNode[]>
|
|
183
183
|
extends MathNode {
|
184
184
|
type: 'ArrayNode'
|
185
185
|
isArrayNode: true
|
186
|
-
items: TItems
|
186
|
+
items: [...TItems]
|
187
187
|
}
|
188
188
|
export interface ArrayNodeCtor {
|
189
189
|
new <TItems extends MathNode[] = MathNode[]>(
|
190
|
-
items:
|
190
|
+
items: [...TItems]
|
191
191
|
): ArrayNode<TItems>
|
192
192
|
}
|
193
193
|
|
@@ -283,12 +283,12 @@ export interface FunctionNode<
|
|
283
283
|
type: 'FunctionNode'
|
284
284
|
isFunctionNode: true
|
285
285
|
fn: TFn
|
286
|
-
args: TArgs
|
286
|
+
args: [...TArgs]
|
287
287
|
}
|
288
288
|
export interface FunctionNodeCtor {
|
289
289
|
new <TFn = SymbolNode, TArgs extends MathNode[] = MathNode[]>(
|
290
290
|
fn: TFn,
|
291
|
-
args: TArgs
|
291
|
+
args: [...TArgs]
|
292
292
|
): FunctionNode<TFn, TArgs>
|
293
293
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
294
294
|
onUndefinedFunction: (name: string) => any
|
@@ -298,13 +298,13 @@ export interface IndexNode<TDims extends MathNode[] = MathNode[]>
|
|
298
298
|
extends MathNode {
|
299
299
|
type: 'IndexNode'
|
300
300
|
isIndexNode: true
|
301
|
-
dimensions: TDims
|
301
|
+
dimensions: [...TDims]
|
302
302
|
dotNotation: boolean
|
303
303
|
}
|
304
304
|
export interface IndexNodeCtor {
|
305
|
-
new <TDims extends MathNode[] = MathNode[]>(dimensions: TDims): IndexNode
|
305
|
+
new <TDims extends MathNode[] = MathNode[]>(dimensions: [...TDims]): IndexNode
|
306
306
|
new <TDims extends MathNode[] = MathNode[]>(
|
307
|
-
dimensions: TDims,
|
307
|
+
dimensions: [...TDims],
|
308
308
|
dotNotation: boolean
|
309
309
|
): IndexNode<TDims>
|
310
310
|
}
|
@@ -367,7 +367,7 @@ export interface OperatorNode<
|
|
367
367
|
isOperatorNode: true
|
368
368
|
op: TOp
|
369
369
|
fn: TFn
|
370
|
-
args: TArgs
|
370
|
+
args: [...TArgs]
|
371
371
|
implicit: boolean
|
372
372
|
isUnary(): boolean
|
373
373
|
isBinary(): boolean
|
@@ -381,7 +381,7 @@ export interface OperatorNodeCtor extends MathNode {
|
|
381
381
|
>(
|
382
382
|
op: TOp,
|
383
383
|
fn: TFn,
|
384
|
-
args: TArgs,
|
384
|
+
args: [...TArgs],
|
385
385
|
implicit?: boolean
|
386
386
|
): OperatorNode<TOp, TFn, TArgs>
|
387
387
|
}
|
@@ -423,12 +423,12 @@ export interface RelationalNode<TParams extends MathNode[] = MathNode[]>
|
|
423
423
|
type: 'RelationalNode'
|
424
424
|
isRelationalNode: true
|
425
425
|
conditionals: string[]
|
426
|
-
params: TParams
|
426
|
+
params: [...TParams]
|
427
427
|
}
|
428
428
|
export interface RelationalNodeCtor {
|
429
429
|
new <TParams extends MathNode[] = MathNode[]>(
|
430
430
|
conditionals: string[],
|
431
|
-
params: TParams
|
431
|
+
params: [...TParams]
|
432
432
|
): RelationalNode<TParams>
|
433
433
|
}
|
434
434
|
|
@@ -1200,7 +1200,8 @@ export interface MathJsInstance extends MathJsFactory {
|
|
1200
1200
|
* whole matrix.
|
1201
1201
|
* @returns Returns the hypothenuse of the input values.
|
1202
1202
|
*/
|
1203
|
-
hypot<T extends
|
1203
|
+
hypot<T extends number | BigNumber>(...args: T[]): T
|
1204
|
+
hypot<T extends number | BigNumber>(args: T[]): T
|
1204
1205
|
|
1205
1206
|
/**
|
1206
1207
|
* Calculate the least common multiple for two or more values or arrays.
|
@@ -3012,7 +3013,7 @@ export interface MathJsInstance extends MathJsFactory {
|
|
3012
3013
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3013
3014
|
value: any,
|
3014
3015
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3015
|
-
options?: FormatOptions | number | ((item: any) => string),
|
3016
|
+
options?: FormatOptions | number | BigNumber | ((item: any) => string),
|
3016
3017
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3017
3018
|
callback?: (value: any) => string
|
3018
3019
|
): string
|
@@ -3860,8 +3861,10 @@ export interface Matrix {
|
|
3860
3861
|
): void
|
3861
3862
|
toArray(): MathArray
|
3862
3863
|
valueOf(): MathArray
|
3863
|
-
|
3864
|
-
|
3864
|
+
format(
|
3865
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3866
|
+
options?: FormatOptions | number | BigNumber | ((value: any) => string)
|
3867
|
+
): string
|
3865
3868
|
toString(): string
|
3866
3869
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3867
3870
|
toJSON(): any
|
@@ -4252,19 +4255,19 @@ export interface FormatOptions {
|
|
4252
4255
|
* case of notation 'fixed', precision defines the number of significant
|
4253
4256
|
* digits after the decimal point, and is 0 by default.
|
4254
4257
|
*/
|
4255
|
-
precision?: number
|
4258
|
+
precision?: number | BigNumber
|
4256
4259
|
|
4257
4260
|
/**
|
4258
4261
|
* Exponent determining the lower boundary for formatting a value with
|
4259
4262
|
* an exponent when notation='auto. Default value is -3.
|
4260
4263
|
*/
|
4261
|
-
lowerExp?: number
|
4264
|
+
lowerExp?: number | BigNumber
|
4262
4265
|
|
4263
4266
|
/**
|
4264
4267
|
* Exponent determining the upper boundary for formatting a value with
|
4265
4268
|
* an exponent when notation='auto. Default value is 5.
|
4266
4269
|
*/
|
4267
|
-
upperExp?: number
|
4270
|
+
upperExp?: number | BigNumber
|
4268
4271
|
|
4269
4272
|
/**
|
4270
4273
|
* Available values: 'ratio' (default) or 'decimal'. For example
|
@@ -4272,6 +4275,15 @@ export interface FormatOptions {
|
|
4272
4275
|
* and will output 0.(3) when 'decimal' is configured.
|
4273
4276
|
*/
|
4274
4277
|
fraction?: string
|
4278
|
+
|
4279
|
+
/**
|
4280
|
+
* The word size in bits to use for formatting in binary, octal, or
|
4281
|
+
* hexadecimal notation. To be used only with `'bin'`, `'oct'`, or `'hex'`
|
4282
|
+
* values for `notation` option. When this option is defined the value
|
4283
|
+
* is formatted as a signed twos complement integer of the given word
|
4284
|
+
* size and the size suffix is appended to the output.
|
4285
|
+
*/
|
4286
|
+
wordSize?: number | BigNumber
|
4275
4287
|
}
|
4276
4288
|
|
4277
4289
|
export interface Help {
|