mathjs 11.7.0 → 11.8.1
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/HISTORY.md +26 -0
- package/README.md +0 -26
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +2 -2
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/function/typed.js +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesDistance.generated.js +2 -2
- package/lib/cjs/entry/pureFunctionsAny.generated.js +2 -2
- package/lib/cjs/expression/Parser.js +1 -1
- package/lib/cjs/expression/function/parser.js +1 -1
- package/lib/cjs/expression/node/FunctionAssignmentNode.js +1 -1
- package/lib/cjs/expression/node/OperatorNode.js +1 -3
- package/lib/cjs/expression/operators.js +19 -4
- package/lib/cjs/expression/transform/filter.transform.js +4 -13
- package/lib/cjs/expression/transform/forEach.transform.js +3 -12
- package/lib/cjs/expression/transform/map.transform.js +4 -13
- package/lib/cjs/factoriesNumber.js +18 -0
- package/lib/cjs/function/algebra/derivative.js +2 -2
- package/lib/cjs/function/algebra/leafCount.js +1 -1
- package/lib/cjs/function/algebra/polynomialRoot.js +1 -1
- package/lib/cjs/function/algebra/rationalize.js +5 -7
- package/lib/cjs/function/algebra/resolve.js +1 -1
- package/lib/cjs/function/algebra/simplify.js +7 -7
- package/lib/cjs/function/algebra/simplifyConstant.js +3 -3
- package/lib/cjs/function/algebra/simplifyCore.js +2 -2
- package/lib/cjs/function/algebra/sparse/csAmd.js +1 -3
- package/lib/cjs/function/algebra/sparse/csLeaf.js +1 -3
- package/lib/cjs/function/algebra/symbolicEqual.js +8 -8
- package/lib/cjs/function/geometry/distance.js +31 -29
- package/lib/cjs/function/matrix/eigs/complexEigs.js +3 -3
- package/lib/cjs/function/matrix/filter.js +2 -11
- package/lib/cjs/function/matrix/forEach.js +3 -12
- package/lib/cjs/function/matrix/map.js +6 -38
- package/lib/cjs/function/matrix/matrixFromColumns.js +1 -1
- package/lib/cjs/function/matrix/matrixFromRows.js +1 -1
- package/lib/cjs/function/matrix/sqrtm.js +1 -1
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/type/bignumber/function/bignumber.js +7 -0
- package/lib/cjs/type/fraction/function/fraction.js +8 -1
- package/lib/cjs/type/matrix/DenseMatrix.js +41 -45
- package/lib/cjs/type/matrix/SparseMatrix.js +39 -41
- package/lib/cjs/type/number.js +7 -3
- package/lib/cjs/type/unit/Unit.js +2 -0
- package/lib/cjs/type/unit/function/splitUnit.js +1 -1
- package/lib/cjs/utils/applyCallback.js +73 -0
- package/lib/cjs/utils/bignumber/formatter.js +4 -3
- package/lib/cjs/utils/lruQueue.js +2 -6
- package/lib/cjs/utils/map.js +1 -1
- package/lib/cjs/utils/snapshot.js +7 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/function/typed.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesDistance.generated.js +2 -2
- package/lib/esm/entry/pureFunctionsAny.generated.js +2 -2
- package/lib/esm/expression/Parser.js +1 -1
- package/lib/esm/expression/function/parser.js +1 -1
- package/lib/esm/expression/node/OperatorNode.js +1 -3
- package/lib/esm/expression/operators.js +1 -3
- package/lib/esm/expression/transform/filter.transform.js +4 -13
- package/lib/esm/expression/transform/forEach.transform.js +3 -12
- package/lib/esm/expression/transform/map.transform.js +4 -13
- package/lib/esm/function/algebra/derivative.js +2 -2
- package/lib/esm/function/algebra/leafCount.js +1 -1
- package/lib/esm/function/algebra/polynomialRoot.js +1 -1
- package/lib/esm/function/algebra/rationalize.js +5 -7
- package/lib/esm/function/algebra/resolve.js +1 -1
- package/lib/esm/function/algebra/simplify.js +7 -7
- package/lib/esm/function/algebra/simplifyConstant.js +2 -2
- package/lib/esm/function/algebra/simplifyCore.js +2 -2
- package/lib/esm/function/algebra/sparse/csAmd.js +1 -3
- package/lib/esm/function/algebra/sparse/csLeaf.js +1 -3
- package/lib/esm/function/algebra/symbolicEqual.js +8 -8
- package/lib/esm/function/geometry/distance.js +31 -29
- package/lib/esm/function/matrix/eigs/complexEigs.js +2 -2
- package/lib/esm/function/matrix/filter.js +2 -11
- package/lib/esm/function/matrix/forEach.js +3 -12
- package/lib/esm/function/matrix/map.js +6 -38
- package/lib/esm/function/matrix/sqrtm.js +1 -1
- package/lib/esm/type/bignumber/function/bignumber.js +5 -0
- package/lib/esm/type/fraction/function/fraction.js +6 -1
- package/lib/esm/type/number.js +5 -3
- package/lib/esm/type/unit/Unit.js +2 -0
- package/lib/esm/type/unit/function/splitUnit.js +1 -1
- package/lib/esm/utils/applyCallback.js +67 -0
- package/lib/esm/utils/bignumber/formatter.js +4 -3
- package/lib/esm/utils/lruQueue.js +2 -6
- package/lib/esm/version.js +1 -1
- package/package.json +21 -21
- package/types/index.d.ts +16 -16
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isBigNumber } from '../../utils/is.js';
|
|
2
2
|
import { factory } from '../../utils/factory.js';
|
|
3
3
|
var name = 'distance';
|
|
4
|
-
var dependencies = ['typed', 'addScalar', 'subtract', 'divideScalar', 'multiplyScalar', '
|
|
4
|
+
var dependencies = ['typed', 'addScalar', 'subtract', 'divideScalar', 'multiplyScalar', 'deepEqual', 'sqrt', 'abs'];
|
|
5
5
|
export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
6
6
|
var {
|
|
7
7
|
typed,
|
|
@@ -9,7 +9,7 @@ export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
9
9
|
subtract,
|
|
10
10
|
multiplyScalar,
|
|
11
11
|
divideScalar,
|
|
12
|
-
|
|
12
|
+
deepEqual,
|
|
13
13
|
sqrt,
|
|
14
14
|
abs
|
|
15
15
|
} = _ref;
|
|
@@ -23,21 +23,19 @@ export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
23
23
|
* For parametric equation of a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b, c)
|
|
24
24
|
*
|
|
25
25
|
* Syntax:
|
|
26
|
-
*
|
|
27
|
-
* math.distance(
|
|
28
|
-
* math.distance(
|
|
29
|
-
* math.distance(
|
|
30
|
-
* math.distance(
|
|
31
|
-
* math.distance([
|
|
32
|
-
* math.distance([x1,
|
|
33
|
-
* math.distance(
|
|
34
|
-
* math.distance([
|
|
35
|
-
* math.distance(
|
|
36
|
-
* math.distance(
|
|
37
|
-
* math.distance(
|
|
38
|
-
* math.distance(
|
|
39
|
-
* math.distance([x, y, z], [x0, y0, z0, a, b, c])
|
|
40
|
-
* math.distance({pointX: 2, pointY: 5, pointZ: 9}, {x0: 4, y0: 6, z0: 3, a: 4, b: 2, c: 0})
|
|
26
|
+
*
|
|
27
|
+
* math.distance([x1,y1], [x2,y2])
|
|
28
|
+
* math.distance({pointOneX, pointOneY}, {pointTwoX, pointTwoY})
|
|
29
|
+
* math.distance([x1,y1,z1], [x2,y2,z2])
|
|
30
|
+
* math.distance({pointOneX, pointOneY, pointOneZ}, {pointTwoX, pointTwoY, pointTwoZ})
|
|
31
|
+
* math.distance([x1,y1,z1,a1], [x2,y2,z2,a2])
|
|
32
|
+
* math.distance([[x1,y1], [x2,y2], [x3,y3]])
|
|
33
|
+
* math.distance([[x1,y1,z1], [x2,y2,z2], [x3,y3,z3]])
|
|
34
|
+
* math.distance([pointX,pointY], [a,b,c])
|
|
35
|
+
* math.distance([pointX,pointY], [lineOnePtX,lineOnePtY], [lineTwoPtX,lineTwoPtY])
|
|
36
|
+
* math.distance({pointX, pointY}, {lineOnePtX, lineOnePtY}, {lineTwoPtX, lineTwoPtY})
|
|
37
|
+
* math.distance([pointX,pointY,pointZ], [x0, y0, z0, a, b, c])
|
|
38
|
+
* math.distance({pointX, pointY, pointZ}, {x0, y0, z0, a, b, c})
|
|
41
39
|
*
|
|
42
40
|
* Examples:
|
|
43
41
|
* math.distance([0,0], [4,4]) // Returns 5.656854249492381
|
|
@@ -52,11 +50,11 @@ export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
52
50
|
* math.distance([[1, 2], [1, 2], [1, 3]]) // Returns [0, 1, 1]
|
|
53
51
|
* math.distance([[1,2,4], [1,2,6], [8,1,3]]) // Returns [2, 7.14142842854285, 7.681145747868608]
|
|
54
52
|
* math.distance([10, 10], [8, 1, 3]) // Returns 11.535230316796387
|
|
55
|
-
* math.distance([
|
|
53
|
+
* math.distance([0, 0], [3, 0], [0, 4]) // Returns 2.4
|
|
56
54
|
* math.distance(
|
|
57
|
-
* {pointX:
|
|
58
|
-
* {lineOnePtX:
|
|
59
|
-
* {lineTwoPtX:
|
|
55
|
+
* {pointX: 0, pointY: 0},
|
|
56
|
+
* {lineOnePtX: 3, lineOnePtY: 0},
|
|
57
|
+
* {lineTwoPtX: 0, lineTwoPtY: 4}) // Returns 2.4
|
|
60
58
|
* math.distance([2, 3, 1], [1, 1, 2, 5, 0, 1]) // Returns 2.3204774044612857
|
|
61
59
|
* math.distance(
|
|
62
60
|
* {pointX: 2, pointY: 3, pointZ: 1},
|
|
@@ -79,10 +77,12 @@ export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
79
77
|
if (!_2d(z)) {
|
|
80
78
|
throw new TypeError('Array with 2 numbers or BigNumbers expected for third argument');
|
|
81
79
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var
|
|
80
|
+
if (deepEqual(y, z)) {
|
|
81
|
+
throw new TypeError('LinePoint1 should not be same with LinePoint2');
|
|
82
|
+
}
|
|
83
|
+
var xCoeff = subtract(z[1], y[1]);
|
|
84
|
+
var yCoeff = subtract(y[0], z[0]);
|
|
85
|
+
var constant = subtract(multiplyScalar(z[0], y[1]), multiplyScalar(y[0], z[1]));
|
|
86
86
|
return _distancePointLine2D(x[0], x[1], xCoeff, yCoeff, constant);
|
|
87
87
|
} else {
|
|
88
88
|
throw new TypeError('Invalid Arguments: Try again');
|
|
@@ -99,11 +99,13 @@ export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
99
99
|
if (!_2d(z)) {
|
|
100
100
|
throw new TypeError('Values of lineTwoPtX and lineTwoPtY should be numbers or BigNumbers');
|
|
101
101
|
}
|
|
102
|
+
if (deepEqual(_objectToArray(y), _objectToArray(z))) {
|
|
103
|
+
throw new TypeError('LinePoint1 should not be same with LinePoint2');
|
|
104
|
+
}
|
|
102
105
|
if ('pointX' in x && 'pointY' in x && 'lineOnePtX' in y && 'lineOnePtY' in y && 'lineTwoPtX' in z && 'lineTwoPtY' in z) {
|
|
103
|
-
var
|
|
104
|
-
var
|
|
105
|
-
var
|
|
106
|
-
var constant = x.pointX;
|
|
106
|
+
var xCoeff = subtract(z.lineTwoPtY, y.lineOnePtY);
|
|
107
|
+
var yCoeff = subtract(y.lineOnePtX, z.lineTwoPtX);
|
|
108
|
+
var constant = subtract(multiplyScalar(z.lineTwoPtX, y.lineOnePtY), multiplyScalar(y.lineOnePtX, z.lineTwoPtY));
|
|
107
109
|
return _distancePointLine2D(x.pointX, x.pointY, xCoeff, yCoeff, constant);
|
|
108
110
|
} else {
|
|
109
111
|
throw new TypeError('Key names do not match');
|
|
@@ -435,7 +435,7 @@ export function createComplexEigs(_ref) {
|
|
|
435
435
|
|
|
436
436
|
// eigenvalues for which usolve failed (due to numerical error)
|
|
437
437
|
var failedLambdas = [];
|
|
438
|
-
var _loop = function _loop(
|
|
438
|
+
var _loop = function _loop() {
|
|
439
439
|
var λ = uniqueValues[_i4];
|
|
440
440
|
var S = subtract(U, multiply(λ, E)); // the characteristic matrix
|
|
441
441
|
|
|
@@ -459,7 +459,7 @@ export function createComplexEigs(_ref) {
|
|
|
459
459
|
vectors.push(...solutions.map(v => flatten(v)));
|
|
460
460
|
};
|
|
461
461
|
for (var _i4 = 0; _i4 < len; _i4++) {
|
|
462
|
-
_loop(
|
|
462
|
+
_loop();
|
|
463
463
|
}
|
|
464
464
|
if (failedLambdas.length !== 0) {
|
|
465
465
|
var err = new Error('Failed to find eigenvectors for the following eigenvalues: ' + failedLambdas.join(', '));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { applyCallback } from '../../utils/applyCallback.js';
|
|
1
2
|
import { filter, filterRegExp } from '../../utils/array.js';
|
|
2
|
-
import { maxArgumentCount } from '../../utils/function.js';
|
|
3
3
|
import { factory } from '../../utils/factory.js';
|
|
4
4
|
var name = 'filter';
|
|
5
5
|
var dependencies = ['typed'];
|
|
@@ -56,17 +56,8 @@ export var createFilter = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
56
56
|
* @private
|
|
57
57
|
*/
|
|
58
58
|
function _filterCallback(x, callback) {
|
|
59
|
-
// figure out what number of arguments the callback function expects
|
|
60
|
-
var args = maxArgumentCount(callback);
|
|
61
59
|
return filter(x, function (value, index, array) {
|
|
62
60
|
// invoke the callback function with the right number of arguments
|
|
63
|
-
|
|
64
|
-
return callback(value);
|
|
65
|
-
} else if (args === 2) {
|
|
66
|
-
return callback(value, [index]);
|
|
67
|
-
} else {
|
|
68
|
-
// 3 or -1
|
|
69
|
-
return callback(value, [index], array);
|
|
70
|
-
}
|
|
61
|
+
return applyCallback(callback, value, [index], array, 'filter');
|
|
71
62
|
});
|
|
72
63
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { applyCallback } from '../../utils/applyCallback.js';
|
|
2
2
|
import { forEach as forEachArray } from '../../utils/array.js';
|
|
3
3
|
import { factory } from '../../utils/factory.js';
|
|
4
4
|
var name = 'forEach';
|
|
@@ -39,14 +39,12 @@ export var createForEach = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
* forEach for a
|
|
42
|
+
* forEach for a multidimensional array
|
|
43
43
|
* @param {Array} array
|
|
44
44
|
* @param {Function} callback
|
|
45
45
|
* @private
|
|
46
46
|
*/
|
|
47
47
|
function _forEach(array, callback) {
|
|
48
|
-
// figure out what number of arguments the callback function expects
|
|
49
|
-
var args = maxArgumentCount(callback);
|
|
50
48
|
var recurse = function recurse(value, index) {
|
|
51
49
|
if (Array.isArray(value)) {
|
|
52
50
|
forEachArray(value, function (child, i) {
|
|
@@ -55,14 +53,7 @@ function _forEach(array, callback) {
|
|
|
55
53
|
});
|
|
56
54
|
} else {
|
|
57
55
|
// invoke the callback function with the right number of arguments
|
|
58
|
-
|
|
59
|
-
callback(value);
|
|
60
|
-
} else if (args === 2) {
|
|
61
|
-
callback(value, index);
|
|
62
|
-
} else {
|
|
63
|
-
// 3 or -1
|
|
64
|
-
callback(value, index, array);
|
|
65
|
-
}
|
|
56
|
+
return applyCallback(callback, value, index, array, 'forEach');
|
|
66
57
|
}
|
|
67
58
|
};
|
|
68
59
|
recurse(array, []);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { applyCallback } from '../../utils/applyCallback.js';
|
|
2
2
|
import { factory } from '../../utils/factory.js';
|
|
3
3
|
var name = 'map';
|
|
4
4
|
var dependencies = ['typed'];
|
|
@@ -27,14 +27,9 @@ export var createMap = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
27
27
|
* return value * value
|
|
28
28
|
* }) // returns [1, 4, 9]
|
|
29
29
|
*
|
|
30
|
-
* // The
|
|
31
|
-
*
|
|
32
|
-
* //
|
|
33
|
-
* // [This happens because `format` _can_ take a second argument,
|
|
34
|
-
* // but its semantics don't match that of the 2nd argument `map` provides]
|
|
35
|
-
*
|
|
36
|
-
* // To avoid this error, use a function that takes exactly the
|
|
37
|
-
* // desired arguments:
|
|
30
|
+
* // The callback is normally called with three arguments:
|
|
31
|
+
* // callback(value, index, Array)
|
|
32
|
+
* // If you want to call with only one argument, use:
|
|
38
33
|
* math.map([1, 2, 3], x => math.format(x)) // returns ['1', '2', '3']
|
|
39
34
|
*
|
|
40
35
|
* See also:
|
|
@@ -63,8 +58,6 @@ export var createMap = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
63
58
|
* @private
|
|
64
59
|
*/
|
|
65
60
|
function _map(array, callback) {
|
|
66
|
-
// figure out what number of arguments the callback function expects
|
|
67
|
-
var args = maxArgumentCount(callback);
|
|
68
61
|
var recurse = function recurse(value, index) {
|
|
69
62
|
if (Array.isArray(value)) {
|
|
70
63
|
return value.map(function (child, i) {
|
|
@@ -72,33 +65,8 @@ function _map(array, callback) {
|
|
|
72
65
|
return recurse(child, index.concat(i));
|
|
73
66
|
});
|
|
74
67
|
} else {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (args === 1) {
|
|
78
|
-
return callback(value);
|
|
79
|
-
} else if (args === 2) {
|
|
80
|
-
return callback(value, index);
|
|
81
|
-
} else {
|
|
82
|
-
// 3 or -1
|
|
83
|
-
return callback(value, index, array);
|
|
84
|
-
}
|
|
85
|
-
} catch (err) {
|
|
86
|
-
// But maybe the arguments still weren't right
|
|
87
|
-
if (err instanceof TypeError && 'data' in err && err.data.category === 'wrongType') {
|
|
88
|
-
var newmsg = "map attempted to call '".concat(err.data.fn, "(").concat(value);
|
|
89
|
-
var indexString = JSON.stringify(index);
|
|
90
|
-
if (args === 2) {
|
|
91
|
-
newmsg += ',' + indexString;
|
|
92
|
-
} else if (args !== 1) {
|
|
93
|
-
newmsg += ",".concat(indexString, ",").concat(array);
|
|
94
|
-
}
|
|
95
|
-
newmsg += ")' but argument ".concat(err.data.index + 1, " of type ");
|
|
96
|
-
newmsg += "".concat(err.data.actual, " does not match expected type ");
|
|
97
|
-
newmsg += err.data.expected.join(' or ');
|
|
98
|
-
throw new TypeError(newmsg);
|
|
99
|
-
}
|
|
100
|
-
throw err;
|
|
101
|
-
}
|
|
68
|
+
// invoke the callback function with the right number of arguments
|
|
69
|
+
return applyCallback(callback, value, index, array, 'map');
|
|
102
70
|
}
|
|
103
71
|
};
|
|
104
72
|
return recurse(array, []);
|
|
@@ -63,6 +63,11 @@ export var createBignumber = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
63
63
|
// we assume a BigNumber is immutable
|
|
64
64
|
return x;
|
|
65
65
|
},
|
|
66
|
+
Unit: typed.referToSelf(self => x => {
|
|
67
|
+
var clone = x.clone();
|
|
68
|
+
clone.value = self(x.value);
|
|
69
|
+
return clone;
|
|
70
|
+
}),
|
|
66
71
|
Fraction: function Fraction(x) {
|
|
67
72
|
return new BigNumber(x.n).div(x.d).times(x.s);
|
|
68
73
|
},
|
|
@@ -39,7 +39,7 @@ export var createFraction = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
39
39
|
*
|
|
40
40
|
* bignumber, number, string, unit
|
|
41
41
|
*
|
|
42
|
-
* @param {number | string | Fraction | BigNumber | Array | Matrix} [args]
|
|
42
|
+
* @param {number | string | Fraction | BigNumber | Unit | Array | Matrix} [args]
|
|
43
43
|
* Arguments specifying the value, or numerator and denominator of
|
|
44
44
|
* the fraction
|
|
45
45
|
* @return {Fraction | Array | Matrix} Returns a fraction
|
|
@@ -67,6 +67,11 @@ export var createFraction = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
67
67
|
return x; // fractions are immutable
|
|
68
68
|
},
|
|
69
69
|
|
|
70
|
+
Unit: typed.referToSelf(self => x => {
|
|
71
|
+
var clone = x.clone();
|
|
72
|
+
clone.value = self(x.value);
|
|
73
|
+
return clone;
|
|
74
|
+
}),
|
|
70
75
|
Object: function Object(x) {
|
|
71
76
|
return new Fraction(x);
|
|
72
77
|
},
|
package/lib/esm/type/number.js
CHANGED
|
@@ -121,9 +121,11 @@ export var createNumber = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
121
121
|
Fraction: function Fraction(x) {
|
|
122
122
|
return x.valueOf();
|
|
123
123
|
},
|
|
124
|
-
Unit:
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
Unit: typed.referToSelf(self => x => {
|
|
125
|
+
var clone = x.clone();
|
|
126
|
+
clone.value = self(x.value);
|
|
127
|
+
return clone;
|
|
128
|
+
}),
|
|
127
129
|
null: function _null(x) {
|
|
128
130
|
return 0;
|
|
129
131
|
},
|
|
@@ -3260,6 +3260,8 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
3260
3260
|
watts: 'watt',
|
|
3261
3261
|
joules: 'joule',
|
|
3262
3262
|
amperes: 'ampere',
|
|
3263
|
+
amps: 'ampere',
|
|
3264
|
+
amp: 'ampere',
|
|
3263
3265
|
coulombs: 'coulomb',
|
|
3264
3266
|
volts: 'volt',
|
|
3265
3267
|
ohms: 'ohm',
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import typed from 'typed-function';
|
|
2
|
+
import { typeOf as _typeOf } from './is.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Invoke a callback for functions like map and filter with a matching number of arguments
|
|
6
|
+
* @param {function} callback
|
|
7
|
+
* @param {any} value
|
|
8
|
+
* @param {number | number[]} index
|
|
9
|
+
* @param {Array} array
|
|
10
|
+
* @param {string} mappingFnName The name of the function that is invoking these callbacks, for example "map" or "filter"
|
|
11
|
+
* @returns {*}
|
|
12
|
+
*/
|
|
13
|
+
export function applyCallback(callback, value, index, array, mappingFnName) {
|
|
14
|
+
if (typed.isTypedFunction(callback)) {
|
|
15
|
+
// invoke the typed callback function with the matching number of arguments only
|
|
16
|
+
|
|
17
|
+
var args3 = [value, index, array];
|
|
18
|
+
var signature3 = typed.resolve(callback, args3);
|
|
19
|
+
if (signature3) {
|
|
20
|
+
return tryWithArgs(signature3.implementation, args3);
|
|
21
|
+
}
|
|
22
|
+
var args2 = [value, index];
|
|
23
|
+
var signature2 = typed.resolve(callback, args2);
|
|
24
|
+
if (signature2) {
|
|
25
|
+
return tryWithArgs(signature2.implementation, args2);
|
|
26
|
+
}
|
|
27
|
+
var args1 = [value];
|
|
28
|
+
var signature1 = typed.resolve(callback, args1);
|
|
29
|
+
if (signature1) {
|
|
30
|
+
return tryWithArgs(signature1.implementation, args1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// fallback (will throw an exception)
|
|
34
|
+
return tryWithArgs(callback, args3);
|
|
35
|
+
} else {
|
|
36
|
+
// A regular JavaScript function
|
|
37
|
+
return callback(value, index, array);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {function} signature The selected signature of the typed-function
|
|
42
|
+
* @param {Array} args List with arguments to apply to the selected signature
|
|
43
|
+
* @returns {*} Returns the return value of the invoked signature
|
|
44
|
+
* @throws {TypeError} Throws an error when no matching signature was found
|
|
45
|
+
*/
|
|
46
|
+
function tryWithArgs(signature, args) {
|
|
47
|
+
try {
|
|
48
|
+
return signature.apply(signature, args);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
var _err$data;
|
|
51
|
+
// Enrich the error message so the user understands that it took place inside the callback function
|
|
52
|
+
if (err instanceof TypeError && ((_err$data = err.data) === null || _err$data === void 0 ? void 0 : _err$data.category) === 'wrongType') {
|
|
53
|
+
var argsDesc = [];
|
|
54
|
+
argsDesc.push("value: ".concat(_typeOf(value)));
|
|
55
|
+
if (args.length >= 2) {
|
|
56
|
+
argsDesc.push("index: ".concat(_typeOf(index)));
|
|
57
|
+
}
|
|
58
|
+
if (args.length >= 3) {
|
|
59
|
+
argsDesc.push("array: ".concat(_typeOf(array)));
|
|
60
|
+
}
|
|
61
|
+
throw new TypeError("Function ".concat(mappingFnName, " cannot apply callback arguments ") + "".concat(callback.name, "(").concat(argsDesc.join(', '), ") at index ").concat(JSON.stringify(index)));
|
|
62
|
+
} else {
|
|
63
|
+
throw new TypeError("Function ".concat(mappingFnName, " cannot apply callback arguments ") + "to function ".concat(callback.name, ": ").concat(err.message));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -146,7 +146,7 @@ export function format(value, options) {
|
|
|
146
146
|
// determine precision from options
|
|
147
147
|
if (typeof options === 'number') {
|
|
148
148
|
precision = options;
|
|
149
|
-
} else if (options.precision) {
|
|
149
|
+
} else if (options.precision !== undefined) {
|
|
150
150
|
precision = options.precision;
|
|
151
151
|
}
|
|
152
152
|
if (options.wordSize) {
|
|
@@ -207,7 +207,7 @@ export function format(value, options) {
|
|
|
207
207
|
|
|
208
208
|
/**
|
|
209
209
|
* Format a BigNumber in engineering notation. Like '1.23e+6', '2.3e+0', '3.500e-3'
|
|
210
|
-
* @param {BigNumber
|
|
210
|
+
* @param {BigNumber} value
|
|
211
211
|
* @param {number} [precision] Optional number of significant figures to return.
|
|
212
212
|
*/
|
|
213
213
|
export function toEngineering(value, precision) {
|
|
@@ -219,7 +219,8 @@ export function toEngineering(value, precision) {
|
|
|
219
219
|
var valueWithoutExp = value.mul(Math.pow(10, -newExp));
|
|
220
220
|
var valueStr = valueWithoutExp.toPrecision(precision);
|
|
221
221
|
if (valueStr.indexOf('e') !== -1) {
|
|
222
|
-
|
|
222
|
+
var BigNumber = value.constructor;
|
|
223
|
+
valueStr = new BigNumber(valueStr).toFixed();
|
|
223
224
|
}
|
|
224
225
|
return valueStr + 'e' + (e >= 0 ? '+' : '') + newExp.toString();
|
|
225
226
|
}
|
|
@@ -19,9 +19,7 @@ export function lruQueue(limit) {
|
|
|
19
19
|
base = 1;
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
while (!hasOwnProperty.call(queue, ++base))
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
22
|
+
while (!hasOwnProperty.call(queue, ++base)) continue;
|
|
25
23
|
};
|
|
26
24
|
limit = Math.abs(limit);
|
|
27
25
|
return {
|
|
@@ -39,9 +37,7 @@ export function lruQueue(limit) {
|
|
|
39
37
|
}
|
|
40
38
|
delete queue[oldIndex];
|
|
41
39
|
if (base !== oldIndex) return undefined;
|
|
42
|
-
while (!hasOwnProperty.call(queue, ++base))
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
40
|
+
while (!hasOwnProperty.call(queue, ++base)) continue;
|
|
45
41
|
return undefined;
|
|
46
42
|
},
|
|
47
43
|
delete: del,
|
package/lib/esm/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mathjs",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.8.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.
|
|
28
|
+
"@babel/runtime": "^7.22.5",
|
|
29
29
|
"complex.js": "^2.1.1",
|
|
30
30
|
"decimal.js": "^10.4.3",
|
|
31
31
|
"escape-latex": "^1.2.0",
|
|
@@ -36,32 +36,32 @@
|
|
|
36
36
|
"typed-function": "^4.1.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@babel/core": "7.
|
|
40
|
-
"@babel/plugin-transform-object-assign": "7.
|
|
41
|
-
"@babel/plugin-transform-runtime": "7.
|
|
42
|
-
"@babel/preset-env": "7.
|
|
43
|
-
"@babel/register": "7.
|
|
39
|
+
"@babel/core": "7.22.5",
|
|
40
|
+
"@babel/plugin-transform-object-assign": "7.22.5",
|
|
41
|
+
"@babel/plugin-transform-runtime": "7.22.5",
|
|
42
|
+
"@babel/preset-env": "7.22.5",
|
|
43
|
+
"@babel/register": "7.22.5",
|
|
44
44
|
"@types/assert": "1.5.6",
|
|
45
45
|
"@types/mocha": "10.0.1",
|
|
46
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
47
|
-
"@typescript-eslint/parser": "5.
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "5.59.11",
|
|
47
|
+
"@typescript-eslint/parser": "5.59.11",
|
|
48
48
|
"assert": "2.0.0",
|
|
49
49
|
"babel-loader": "9.1.2",
|
|
50
50
|
"benchmark": "2.1.4",
|
|
51
|
-
"c8": "7.
|
|
51
|
+
"c8": "7.14.0",
|
|
52
52
|
"codecov": "3.8.3",
|
|
53
|
-
"core-js": "3.
|
|
53
|
+
"core-js": "3.31.0",
|
|
54
54
|
"del": "6.1.1",
|
|
55
55
|
"dtslint": "4.2.1",
|
|
56
|
-
"eslint": "8.
|
|
57
|
-
"eslint-config-prettier": "8.
|
|
58
|
-
"eslint-config-standard": "17.
|
|
56
|
+
"eslint": "8.42.0",
|
|
57
|
+
"eslint-config-prettier": "8.8.0",
|
|
58
|
+
"eslint-config-standard": "17.1.0",
|
|
59
59
|
"eslint-plugin-import": "2.27.5",
|
|
60
60
|
"eslint-plugin-mocha": "10.1.0",
|
|
61
|
-
"eslint-plugin-n": "
|
|
61
|
+
"eslint-plugin-n": "16.0.0",
|
|
62
62
|
"eslint-plugin-prettier": "4.2.1",
|
|
63
63
|
"eslint-plugin-promise": "6.1.1",
|
|
64
|
-
"expect-type": "0.
|
|
64
|
+
"expect-type": "0.16.0",
|
|
65
65
|
"expr-eval": "2.0.2",
|
|
66
66
|
"fancy-log": "2.0.0",
|
|
67
67
|
"glob": "8.1.0",
|
|
@@ -69,13 +69,13 @@
|
|
|
69
69
|
"gulp-babel": "8.0.0",
|
|
70
70
|
"handlebars": "4.7.7",
|
|
71
71
|
"jsep": "1.3.8",
|
|
72
|
-
"karma": "6.4.
|
|
72
|
+
"karma": "6.4.2",
|
|
73
73
|
"karma-browserstack-launcher": "1.6.0",
|
|
74
74
|
"karma-firefox-launcher": "2.1.2",
|
|
75
75
|
"karma-mocha": "2.0.1",
|
|
76
76
|
"karma-mocha-reporter": "2.2.5",
|
|
77
77
|
"karma-webpack": "5.0.0",
|
|
78
|
-
"mkdirp": "2.1.
|
|
78
|
+
"mkdirp": "2.1.6",
|
|
79
79
|
"mocha": "10.2.0",
|
|
80
80
|
"mocha-junit-reporter": "2.2.0",
|
|
81
81
|
"ndarray": "1.0.19",
|
|
@@ -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": "2.8.
|
|
88
|
+
"prettier": "2.8.8",
|
|
89
89
|
"process": "0.11.10",
|
|
90
90
|
"sylvester": "0.0.21",
|
|
91
91
|
"ts-node": "10.9.1",
|
|
92
|
-
"typescript": "
|
|
93
|
-
"webpack": "5.
|
|
92
|
+
"typescript": "5.1.3",
|
|
93
|
+
"webpack": "5.86.0",
|
|
94
94
|
"zeros": "1.0.0"
|
|
95
95
|
},
|
|
96
96
|
"type": "module",
|