mathjs 13.2.3 → 14.0.0
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 +18 -0
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +1 -9
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/function/import.js +4 -1
- package/lib/cjs/core/function/typed.js +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesBitXor.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesDotDivide.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesDotPow.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesEqual.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesLargerEq.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesLog.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSmallerEq.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesUnequal.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesXor.generated.js +2 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +1 -0
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +1 -0
- package/lib/cjs/entry/pureFunctionsAny.generated.js +11 -0
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/ceil.js +2 -2
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/fix.js +2 -2
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/floor.js +2 -2
- package/lib/cjs/expression/parse.js +26 -36
- package/lib/cjs/function/algebra/simplify.js +4 -3
- package/lib/cjs/function/algebra/simplifyConstant.js +5 -11
- package/lib/cjs/function/arithmetic/ceil.js +21 -2
- package/lib/cjs/function/arithmetic/dotDivide.js +4 -3
- package/lib/cjs/function/arithmetic/dotPow.js +4 -3
- package/lib/cjs/function/arithmetic/fix.js +24 -5
- package/lib/cjs/function/arithmetic/floor.js +21 -2
- package/lib/cjs/function/arithmetic/log.js +12 -4
- package/lib/cjs/function/arithmetic/pow.js +2 -2
- package/lib/cjs/function/arithmetic/round.js +3 -5
- package/lib/cjs/function/arithmetic/sign.js +1 -1
- package/lib/cjs/function/bitwise/bitXor.js +4 -3
- package/lib/cjs/function/logical/xor.js +4 -3
- package/lib/cjs/function/relational/equal.js +4 -3
- package/lib/cjs/function/relational/larger.js +4 -3
- package/lib/cjs/function/relational/largerEq.js +4 -3
- package/lib/cjs/function/relational/smaller.js +4 -3
- package/lib/cjs/function/relational/smallerEq.js +4 -3
- package/lib/cjs/function/relational/unequal.js +4 -3
- package/lib/cjs/function/utils/isInteger.js +1 -1
- package/lib/cjs/function/utils/isNegative.js +1 -1
- package/lib/cjs/function/utils/isPositive.js +1 -1
- package/lib/cjs/header.js +1 -1
- package/lib/cjs/type/bignumber/function/bignumber.js +2 -2
- package/lib/cjs/type/fraction/Fraction.js +4 -4
- package/lib/cjs/type/fraction/function/fraction.js +3 -0
- package/lib/cjs/type/matrix/utils/matAlgo07xSSf.js +39 -43
- package/lib/cjs/type/unit/Unit.js +1 -1
- package/lib/cjs/utils/string.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/function/import.js +4 -1
- package/lib/esm/core/function/typed.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesBitXor.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesDotDivide.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesDotPow.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesEqual.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesLargerEq.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesLog.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSmallerEq.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesUnequal.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesXor.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +1 -0
- package/lib/esm/entry/impureFunctionsNumber.generated.js +1 -0
- package/lib/esm/entry/pureFunctionsAny.generated.js +11 -0
- package/lib/esm/expression/embeddedDocs/function/arithmetic/ceil.js +2 -2
- package/lib/esm/expression/embeddedDocs/function/arithmetic/fix.js +2 -2
- package/lib/esm/expression/embeddedDocs/function/arithmetic/floor.js +2 -2
- package/lib/esm/expression/parse.js +26 -36
- package/lib/esm/function/algebra/simplify.js +4 -3
- package/lib/esm/function/algebra/simplifyConstant.js +5 -11
- package/lib/esm/function/arithmetic/ceil.js +21 -2
- package/lib/esm/function/arithmetic/dotDivide.js +4 -3
- package/lib/esm/function/arithmetic/dotPow.js +4 -3
- package/lib/esm/function/arithmetic/fix.js +24 -5
- package/lib/esm/function/arithmetic/floor.js +21 -2
- package/lib/esm/function/arithmetic/log.js +12 -4
- package/lib/esm/function/arithmetic/pow.js +2 -2
- package/lib/esm/function/arithmetic/round.js +3 -5
- package/lib/esm/function/arithmetic/sign.js +1 -1
- package/lib/esm/function/bitwise/bitXor.js +4 -3
- package/lib/esm/function/logical/xor.js +4 -3
- package/lib/esm/function/relational/equal.js +4 -3
- package/lib/esm/function/relational/larger.js +4 -3
- package/lib/esm/function/relational/largerEq.js +4 -3
- package/lib/esm/function/relational/smaller.js +4 -3
- package/lib/esm/function/relational/smallerEq.js +4 -3
- package/lib/esm/function/relational/unequal.js +4 -3
- package/lib/esm/function/utils/isInteger.js +1 -1
- package/lib/esm/function/utils/isNegative.js +1 -1
- package/lib/esm/function/utils/isPositive.js +1 -1
- package/lib/esm/type/bignumber/function/bignumber.js +2 -2
- package/lib/esm/type/fraction/Fraction.js +4 -4
- package/lib/esm/type/fraction/function/fraction.js +3 -0
- package/lib/esm/type/matrix/utils/matAlgo07xSSf.js +39 -43
- package/lib/esm/type/unit/Unit.js +1 -1
- package/lib/esm/utils/string.js +2 -2
- package/lib/esm/version.js +1 -1
- package/package.json +2 -2
- package/types/index.d.ts +110 -18
|
@@ -7,21 +7,22 @@ import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
|
|
|
7
7
|
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
|
|
8
8
|
import { createCompareUnits } from './compareUnits.js';
|
|
9
9
|
var name = 'smallerEq';
|
|
10
|
-
var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
|
|
10
|
+
var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
|
11
11
|
export var createSmallerEq = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
12
12
|
var {
|
|
13
13
|
typed,
|
|
14
14
|
config,
|
|
15
15
|
matrix,
|
|
16
16
|
DenseMatrix,
|
|
17
|
-
concat
|
|
17
|
+
concat,
|
|
18
|
+
SparseMatrix
|
|
18
19
|
} = _ref;
|
|
19
20
|
var matAlgo03xDSf = createMatAlgo03xDSf({
|
|
20
21
|
typed
|
|
21
22
|
});
|
|
22
23
|
var matAlgo07xSSf = createMatAlgo07xSSf({
|
|
23
24
|
typed,
|
|
24
|
-
|
|
25
|
+
SparseMatrix
|
|
25
26
|
});
|
|
26
27
|
var matAlgo12xSfs = createMatAlgo12xSfs({
|
|
27
28
|
typed,
|
|
@@ -4,7 +4,7 @@ import { createMatAlgo07xSSf } from '../../type/matrix/utils/matAlgo07xSSf.js';
|
|
|
4
4
|
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
|
|
5
5
|
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
|
|
6
6
|
var name = 'unequal';
|
|
7
|
-
var dependencies = ['typed', 'config', 'equalScalar', 'matrix', 'DenseMatrix', 'concat'];
|
|
7
|
+
var dependencies = ['typed', 'config', 'equalScalar', 'matrix', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
|
8
8
|
export var createUnequal = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
9
9
|
var {
|
|
10
10
|
typed,
|
|
@@ -12,14 +12,15 @@ export var createUnequal = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
12
12
|
equalScalar,
|
|
13
13
|
matrix,
|
|
14
14
|
DenseMatrix,
|
|
15
|
-
concat
|
|
15
|
+
concat,
|
|
16
|
+
SparseMatrix
|
|
16
17
|
} = _ref;
|
|
17
18
|
var matAlgo03xDSf = createMatAlgo03xDSf({
|
|
18
19
|
typed
|
|
19
20
|
});
|
|
20
21
|
var matAlgo07xSSf = createMatAlgo07xSSf({
|
|
21
22
|
typed,
|
|
22
|
-
|
|
23
|
+
SparseMatrix
|
|
23
24
|
});
|
|
24
25
|
var matAlgo12xSfs = createMatAlgo12xSfs({
|
|
25
26
|
typed,
|
|
@@ -47,7 +47,7 @@ export var createIsInteger = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
47
47
|
return true;
|
|
48
48
|
},
|
|
49
49
|
Fraction: function Fraction(x) {
|
|
50
|
-
return x.d ===
|
|
50
|
+
return x.d === 1n;
|
|
51
51
|
},
|
|
52
52
|
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
|
53
53
|
});
|
|
@@ -43,7 +43,7 @@ export var createIsNegative = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
43
43
|
number: x => nearlyEqual(x, 0, config.relTol, config.absTol) ? false : isNegativeNumber(x),
|
|
44
44
|
BigNumber: x => bigNearlyEqual(x, new x.constructor(0), config.relTol, config.absTol) ? false : x.isNeg() && !x.isZero() && !x.isNaN(),
|
|
45
45
|
bigint: x => x < 0n,
|
|
46
|
-
Fraction: x => x.s <
|
|
46
|
+
Fraction: x => x.s < 0n,
|
|
47
47
|
// It's enough to decide on the sign
|
|
48
48
|
|
|
49
49
|
Unit: typed.referToSelf(self => x => typed.find(self, x.valueType())(x.value)),
|
|
@@ -45,7 +45,7 @@ export var createIsPositive = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
45
45
|
number: x => nearlyEqual(x, 0, config.relTol, config.absTol) ? false : isPositiveNumber(x),
|
|
46
46
|
BigNumber: x => bigNearlyEqual(x, new x.constructor(0), config.relTol, config.absTol) ? false : !x.isNeg() && !x.isZero() && !x.isNaN(),
|
|
47
47
|
bigint: x => x > 0n,
|
|
48
|
-
Fraction: x => x.s >
|
|
48
|
+
Fraction: x => x.s > 0n && x.n > 0n,
|
|
49
49
|
Unit: typed.referToSelf(self => x => typed.find(self, x.valueType())(x.value)),
|
|
50
50
|
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
|
51
51
|
});
|
|
@@ -72,9 +72,9 @@ export var createBignumber = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
72
72
|
return clone;
|
|
73
73
|
}),
|
|
74
74
|
Fraction: function Fraction(x) {
|
|
75
|
-
return new BigNumber(x.n).div(x.d).times(x.s);
|
|
75
|
+
return new BigNumber(String(x.n)).div(String(x.d)).times(String(x.s));
|
|
76
76
|
},
|
|
77
|
-
null: function _null(
|
|
77
|
+
null: function _null(_x) {
|
|
78
78
|
return new BigNumber(0);
|
|
79
79
|
},
|
|
80
80
|
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
|
|
@@ -16,20 +16,20 @@ export var createFractionClass = /* #__PURE__ */factory(name, dependencies, () =
|
|
|
16
16
|
/**
|
|
17
17
|
* Get a JSON representation of a Fraction containing type information
|
|
18
18
|
* @returns {Object} Returns a JSON object structured as:
|
|
19
|
-
* `{"mathjs": "Fraction", "n": 3, "d": 8}`
|
|
19
|
+
* `{"mathjs": "Fraction", "n": "3", "d": "8"}`
|
|
20
20
|
*/
|
|
21
21
|
Fraction.prototype.toJSON = function () {
|
|
22
22
|
return {
|
|
23
23
|
mathjs: 'Fraction',
|
|
24
|
-
n: this.s * this.n,
|
|
25
|
-
d: this.d
|
|
24
|
+
n: String(this.s * this.n),
|
|
25
|
+
d: String(this.d)
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Instantiate a Fraction from a JSON object
|
|
31
31
|
* @param {Object} json a JSON object structured as:
|
|
32
|
-
* `{"mathjs": "Fraction", "n": 3, "d": 8}`
|
|
32
|
+
* `{"mathjs": "Fraction", "n": "3", "d": "8"}`
|
|
33
33
|
* @return {BigNumber}
|
|
34
34
|
*/
|
|
35
35
|
Fraction.fromJSON = function (json) {
|
|
@@ -57,6 +57,9 @@ export var createFraction = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
|
57
57
|
'number, number': function number_number(numerator, denominator) {
|
|
58
58
|
return new Fraction(numerator, denominator);
|
|
59
59
|
},
|
|
60
|
+
'bigint, bigint': function bigint_bigint(numerator, denominator) {
|
|
61
|
+
return new Fraction(numerator, denominator);
|
|
62
|
+
},
|
|
60
63
|
null: function _null(x) {
|
|
61
64
|
return new Fraction(0);
|
|
62
65
|
},
|
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
import { factory } from '../../../utils/factory.js';
|
|
2
2
|
import { DimensionError } from '../../../error/DimensionError.js';
|
|
3
3
|
var name = 'matAlgo07xSSf';
|
|
4
|
-
var dependencies = ['typed', '
|
|
4
|
+
var dependencies = ['typed', 'SparseMatrix'];
|
|
5
5
|
export var createMatAlgo07xSSf = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
6
6
|
var {
|
|
7
7
|
typed,
|
|
8
|
-
|
|
8
|
+
SparseMatrix
|
|
9
9
|
} = _ref;
|
|
10
10
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
* Iterates over SparseMatrix A and SparseMatrix B items (zero and nonzero) and invokes the callback function f(Aij, Bij).
|
|
12
|
+
* Callback function invoked MxN times.
|
|
13
|
+
*
|
|
14
|
+
* C(i,j) = f(Aij, Bij)
|
|
15
|
+
*
|
|
16
|
+
* @param {Matrix} a The SparseMatrix instance (A)
|
|
17
|
+
* @param {Matrix} b The SparseMatrix instance (B)
|
|
18
|
+
* @param {Function} callback The f(Aij,Bij) operation to invoke
|
|
19
|
+
*
|
|
20
|
+
* @return {Matrix} SparseMatrix (C)
|
|
21
|
+
*
|
|
22
|
+
* see https://github.com/josdejong/mathjs/pull/346#issuecomment-97620294
|
|
23
|
+
*/
|
|
24
24
|
return function matAlgo07xSSf(a, b, callback) {
|
|
25
25
|
// sparse matrix arrays
|
|
26
26
|
var asize = a._size;
|
|
27
27
|
var adt = a._datatype || a._data === undefined ? a._datatype : a.getDataType();
|
|
28
|
-
// sparse matrix arrays
|
|
29
28
|
var bsize = b._size;
|
|
30
29
|
var bdt = b._datatype || b._data === undefined ? b._datatype : b.getDataType();
|
|
31
30
|
|
|
@@ -33,8 +32,6 @@ export var createMatAlgo07xSSf = /* #__PURE__ */factory(name, dependencies, _ref
|
|
|
33
32
|
if (asize.length !== bsize.length) {
|
|
34
33
|
throw new DimensionError(asize.length, bsize.length);
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
// check rows & columns
|
|
38
35
|
if (asize[0] !== bsize[0] || asize[1] !== bsize[1]) {
|
|
39
36
|
throw new RangeError('Dimension mismatch. Matrix A (' + asize + ') must match Matrix B (' + bsize + ')');
|
|
40
37
|
}
|
|
@@ -45,59 +42,58 @@ export var createMatAlgo07xSSf = /* #__PURE__ */factory(name, dependencies, _ref
|
|
|
45
42
|
|
|
46
43
|
// datatype
|
|
47
44
|
var dt;
|
|
48
|
-
// zero value
|
|
49
45
|
var zero = 0;
|
|
50
|
-
// callback signature to use
|
|
51
46
|
var cf = callback;
|
|
52
47
|
|
|
53
48
|
// process data types
|
|
54
49
|
if (typeof adt === 'string' && adt === bdt && adt !== 'mixed') {
|
|
55
|
-
// datatype
|
|
56
50
|
dt = adt;
|
|
57
|
-
// convert 0 to the same datatype
|
|
58
51
|
zero = typed.convert(0, dt);
|
|
59
|
-
// callback
|
|
60
52
|
cf = typed.find(callback, [dt, dt]);
|
|
61
53
|
}
|
|
62
54
|
|
|
63
|
-
//
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
//
|
|
67
|
-
var cdata = [];
|
|
68
|
-
// initialize c
|
|
69
|
-
for (i = 0; i < rows; i++) {
|
|
70
|
-
cdata[i] = [];
|
|
71
|
-
}
|
|
55
|
+
// result arrays for sparse format
|
|
56
|
+
var cvalues = [];
|
|
57
|
+
var cindex = [];
|
|
58
|
+
var cptr = new Array(columns + 1).fill(0); // Start with column pointer array
|
|
72
59
|
|
|
73
60
|
// workspaces
|
|
74
61
|
var xa = [];
|
|
75
62
|
var xb = [];
|
|
76
|
-
// marks indicating we have a value in x for a given column
|
|
77
63
|
var wa = [];
|
|
78
64
|
var wb = [];
|
|
79
65
|
|
|
80
66
|
// loop columns
|
|
81
|
-
for (j = 0; j < columns; j++) {
|
|
82
|
-
// columns mark
|
|
67
|
+
for (var j = 0; j < columns; j++) {
|
|
83
68
|
var mark = j + 1;
|
|
84
|
-
|
|
69
|
+
var nonZeroCount = 0;
|
|
85
70
|
_scatter(a, j, wa, xa, mark);
|
|
86
|
-
// scatter the values of B(:,j) into workspace
|
|
87
71
|
_scatter(b, j, wb, xb, mark);
|
|
72
|
+
|
|
88
73
|
// loop rows
|
|
89
|
-
for (i = 0; i < rows; i++) {
|
|
90
|
-
// matrix values @ i,j
|
|
74
|
+
for (var i = 0; i < rows; i++) {
|
|
91
75
|
var va = wa[i] === mark ? xa[i] : zero;
|
|
92
76
|
var vb = wb[i] === mark ? xb[i] : zero;
|
|
77
|
+
|
|
93
78
|
// invoke callback
|
|
94
|
-
|
|
79
|
+
var cij = cf(va, vb);
|
|
80
|
+
// Store all non zero and true values
|
|
81
|
+
if (cij !== 0 && cij !== false) {
|
|
82
|
+
cindex.push(i); // row index
|
|
83
|
+
cvalues.push(cij); // computed value
|
|
84
|
+
nonZeroCount++;
|
|
85
|
+
}
|
|
95
86
|
}
|
|
87
|
+
|
|
88
|
+
// Update column pointer with cumulative count of non-zero values
|
|
89
|
+
cptr[j + 1] = cptr[j] + nonZeroCount;
|
|
96
90
|
}
|
|
97
91
|
|
|
98
|
-
//
|
|
99
|
-
return new
|
|
100
|
-
|
|
92
|
+
// Return the result as a sparse matrix
|
|
93
|
+
return new SparseMatrix({
|
|
94
|
+
values: cvalues,
|
|
95
|
+
index: cindex,
|
|
96
|
+
ptr: cptr,
|
|
101
97
|
size: [rows, columns],
|
|
102
98
|
datatype: adt === a._datatype && bdt === b._datatype ? dt : undefined
|
|
103
99
|
});
|
|
@@ -3533,7 +3533,7 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
|
3533
3533
|
*/
|
|
3534
3534
|
Unit.typeConverters = {
|
|
3535
3535
|
BigNumber: function BigNumber(x) {
|
|
3536
|
-
if (x !== null && x !== void 0 && x.isFraction) return new _BigNumber(x.n).div(x.d).times(x.s);
|
|
3536
|
+
if (x !== null && x !== void 0 && x.isFraction) return new _BigNumber(String(x.n)).div(String(x.d)).times(String(x.s));
|
|
3537
3537
|
return new _BigNumber(x + ''); // stringify to prevent constructor error
|
|
3538
3538
|
},
|
|
3539
3539
|
Fraction: function Fraction(x) {
|
package/lib/esm/utils/string.js
CHANGED
|
@@ -71,7 +71,7 @@ function _format(value, options) {
|
|
|
71
71
|
if (looksLikeFraction(value)) {
|
|
72
72
|
if (!options || options.fraction !== 'decimal') {
|
|
73
73
|
// output as ratio, like '1/3'
|
|
74
|
-
return value.s * value.n
|
|
74
|
+
return "".concat(value.s * value.n, "/").concat(value.d);
|
|
75
75
|
} else {
|
|
76
76
|
// output as decimal, like '0.(3)'
|
|
77
77
|
return value.toString();
|
|
@@ -173,7 +173,7 @@ function formatArray(array, options) {
|
|
|
173
173
|
* @return {boolean}
|
|
174
174
|
*/
|
|
175
175
|
function looksLikeFraction(value) {
|
|
176
|
-
return value && typeof value === 'object' && typeof value.s === '
|
|
176
|
+
return value && typeof value === 'object' && typeof value.s === 'bigint' && typeof value.n === 'bigint' && typeof value.d === 'bigint' || false;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
/**
|
package/lib/esm/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mathjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
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",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"complex.js": "^2.2.5",
|
|
30
30
|
"decimal.js": "^10.4.3",
|
|
31
31
|
"escape-latex": "^1.2.0",
|
|
32
|
-
"fraction.js": "^
|
|
32
|
+
"fraction.js": "^5.2.1",
|
|
33
33
|
"javascript-natural-sort": "^0.7.1",
|
|
34
34
|
"seedrandom": "^3.0.5",
|
|
35
35
|
"tiny-emitter": "^2.1.0",
|
package/types/index.d.ts
CHANGED
|
@@ -10,11 +10,11 @@ export type NoLiteralType<T> = T extends number
|
|
|
10
10
|
? boolean
|
|
11
11
|
: T
|
|
12
12
|
|
|
13
|
-
// TODO: introduce generics for MathCollection, MathMatrix, and MathArray
|
|
14
13
|
export type MathNumericType = number | BigNumber | bigint | Fraction | Complex
|
|
15
14
|
export type MathScalarType = MathNumericType | Unit
|
|
16
|
-
export type
|
|
17
|
-
export type
|
|
15
|
+
export type MathGeneric<T extends MathScalarType = MathNumericType> = T
|
|
16
|
+
export type MathArray<T = MathGeneric> = T[] | Array<MathArray<T>>
|
|
17
|
+
export type MathCollection<T = MathGeneric> = MathArray<T> | Matrix<T>
|
|
18
18
|
export type MathType = MathScalarType | MathCollection
|
|
19
19
|
export type MathExpression = string | string[] | MathCollection
|
|
20
20
|
|
|
@@ -719,6 +719,7 @@ export interface MathJsInstance extends MathJsFactory {
|
|
|
719
719
|
* fraction
|
|
720
720
|
* @returns Returns a fraction
|
|
721
721
|
*/
|
|
722
|
+
fraction(numerator: bigint, denominator: bigint): Fraction
|
|
722
723
|
fraction(numerator: number, denominator: number): Fraction
|
|
723
724
|
|
|
724
725
|
/**
|
|
@@ -751,6 +752,11 @@ export interface MathJsInstance extends MathJsFactory {
|
|
|
751
752
|
format?: 'sparse' | 'dense',
|
|
752
753
|
dataType?: string
|
|
753
754
|
): Matrix
|
|
755
|
+
matrix<T extends MathScalarType>(
|
|
756
|
+
data: MathCollection<T>,
|
|
757
|
+
format?: 'sparse' | 'dense',
|
|
758
|
+
dataType?: string
|
|
759
|
+
): Matrix<T>
|
|
754
760
|
|
|
755
761
|
/**
|
|
756
762
|
* Create a number or convert a string, boolean, or unit to a number.
|
|
@@ -1147,6 +1153,14 @@ export interface MathJsInstance extends MathJsFactory {
|
|
|
1147
1153
|
n?: number | BigNumber
|
|
1148
1154
|
): NoLiteralType<T>
|
|
1149
1155
|
ceil<U extends MathCollection>(x: MathNumericType, n: U): U
|
|
1156
|
+
ceil<U extends MathCollection<Unit>>(x: U, unit: Unit): U
|
|
1157
|
+
ceil(x: Unit, unit: Unit): Unit
|
|
1158
|
+
ceil(x: Unit, n: number | BigNumber, unit: Unit): Unit
|
|
1159
|
+
ceil<U extends MathCollection<Unit>>(
|
|
1160
|
+
x: U,
|
|
1161
|
+
n: number | BigNumber,
|
|
1162
|
+
unit: Unit
|
|
1163
|
+
): U
|
|
1150
1164
|
|
|
1151
1165
|
/**
|
|
1152
1166
|
* Round a value towards zero. For matrices, the function is evaluated
|
|
@@ -1160,6 +1174,14 @@ export interface MathJsInstance extends MathJsFactory {
|
|
|
1160
1174
|
n?: number | BigNumber
|
|
1161
1175
|
): NoLiteralType<T>
|
|
1162
1176
|
fix<U extends MathCollection>(x: MathNumericType, n: U): U
|
|
1177
|
+
fix<U extends MathCollection<Unit>>(x: U, unit: Unit): U
|
|
1178
|
+
fix(x: Unit, unit: Unit): Unit
|
|
1179
|
+
fix(x: Unit, n: number | BigNumber, unit: Unit): Unit
|
|
1180
|
+
fix<U extends MathCollection<Unit>>(
|
|
1181
|
+
x: U,
|
|
1182
|
+
n: number | BigNumber,
|
|
1183
|
+
unit: Unit
|
|
1184
|
+
): U
|
|
1163
1185
|
|
|
1164
1186
|
/**
|
|
1165
1187
|
* Round a value towards minus infinity. For matrices, the function is
|
|
@@ -1173,6 +1195,14 @@ export interface MathJsInstance extends MathJsFactory {
|
|
|
1173
1195
|
n?: number | BigNumber
|
|
1174
1196
|
): NoLiteralType<T>
|
|
1175
1197
|
floor<U extends MathCollection>(x: MathNumericType, n: U): U
|
|
1198
|
+
floor<U extends MathCollection<Unit>>(x: U, unit: Unit): U
|
|
1199
|
+
floor(x: Unit, unit: Unit): Unit
|
|
1200
|
+
floor(x: Unit, n: number | BigNumber, unit: Unit): Unit
|
|
1201
|
+
floor<U extends MathCollection<Unit>>(
|
|
1202
|
+
x: U,
|
|
1203
|
+
n: number | BigNumber,
|
|
1204
|
+
unit: Unit
|
|
1205
|
+
): U
|
|
1176
1206
|
|
|
1177
1207
|
/**
|
|
1178
1208
|
* Round a value towards the nearest integer. For matrices, the function
|
|
@@ -1186,10 +1216,14 @@ export interface MathJsInstance extends MathJsFactory {
|
|
|
1186
1216
|
n?: number | BigNumber
|
|
1187
1217
|
): NoLiteralType<T>
|
|
1188
1218
|
round<U extends MathCollection>(x: MathNumericType, n: U): U
|
|
1189
|
-
round<U extends MathCollection
|
|
1219
|
+
round<U extends MathCollection<Unit>>(x: U, unit: Unit): U
|
|
1190
1220
|
round(x: Unit, unit: Unit): Unit
|
|
1191
1221
|
round(x: Unit, n: number | BigNumber, unit: Unit): Unit
|
|
1192
|
-
round<U extends MathCollection
|
|
1222
|
+
round<U extends MathCollection<Unit>>(
|
|
1223
|
+
x: U,
|
|
1224
|
+
n: number | BigNumber,
|
|
1225
|
+
unit: Unit
|
|
1226
|
+
): U
|
|
1193
1227
|
|
|
1194
1228
|
// End of group of rounding functions
|
|
1195
1229
|
|
|
@@ -1359,9 +1393,10 @@ export interface MathJsInstance extends MathJsFactory {
|
|
|
1359
1393
|
multiply<T extends Matrix>(x: T, y: MathType): Matrix
|
|
1360
1394
|
multiply<T extends Matrix>(x: MathType, y: T): Matrix
|
|
1361
1395
|
|
|
1362
|
-
multiply<T extends
|
|
1363
|
-
multiply<T extends
|
|
1364
|
-
multiply<T extends MathArray>(x: T, y: T): T
|
|
1396
|
+
multiply<T extends MathArray>(x: T, y: T[]): T
|
|
1397
|
+
multiply<T extends MathArray>(x: T[], y: T): T
|
|
1398
|
+
multiply<T extends MathArray>(x: T[], y: T[]): T
|
|
1399
|
+
multiply<T extends MathArray>(x: T, y: T): MathScalarType
|
|
1365
1400
|
multiply(x: Unit, y: Unit): Unit
|
|
1366
1401
|
multiply(x: number, y: number): number
|
|
1367
1402
|
multiply(x: MathType, y: MathType): MathType
|
|
@@ -3964,7 +3999,7 @@ export const {
|
|
|
3964
3999
|
varianceTransformDependencies
|
|
3965
4000
|
}: Record<string, FactoryFunctionMap>
|
|
3966
4001
|
|
|
3967
|
-
export interface Matrix {
|
|
4002
|
+
export interface Matrix<T = MathGeneric> {
|
|
3968
4003
|
type: string
|
|
3969
4004
|
storage(): string
|
|
3970
4005
|
datatype(): string
|
|
@@ -3981,7 +4016,7 @@ export interface Matrix {
|
|
|
3981
4016
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3982
4017
|
set(index: number[], value: any, defaultValue?: number | string): Matrix
|
|
3983
4018
|
resize(size: MathCollection, defaultValue?: number | string): Matrix
|
|
3984
|
-
clone(): Matrix
|
|
4019
|
+
clone(): Matrix<T>
|
|
3985
4020
|
size(): number[]
|
|
3986
4021
|
map(
|
|
3987
4022
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -3993,8 +4028,8 @@ export interface Matrix {
|
|
|
3993
4028
|
callback: (a: any, b: number[], c: Matrix) => void,
|
|
3994
4029
|
skipZeros?: boolean
|
|
3995
4030
|
): void
|
|
3996
|
-
toArray(): MathArray
|
|
3997
|
-
valueOf(): MathArray
|
|
4031
|
+
toArray(): MathArray<T>
|
|
4032
|
+
valueOf(): MathArray<T>
|
|
3998
4033
|
format(
|
|
3999
4034
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4000
4035
|
options?: FormatOptions | number | BigNumber | ((value: any) => string)
|
|
@@ -4004,7 +4039,7 @@ export interface Matrix {
|
|
|
4004
4039
|
toJSON(): any
|
|
4005
4040
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4006
4041
|
diagonal(k?: number | BigNumber): any[]
|
|
4007
|
-
swapRows(i: number, j: number): Matrix
|
|
4042
|
+
swapRows(i: number, j: number): Matrix<T>
|
|
4008
4043
|
}
|
|
4009
4044
|
|
|
4010
4045
|
export interface MatrixCtor {
|
|
@@ -4015,9 +4050,9 @@ export interface MatrixCtor {
|
|
|
4015
4050
|
export interface BigNumber extends Decimal {}
|
|
4016
4051
|
|
|
4017
4052
|
export interface Fraction {
|
|
4018
|
-
s:
|
|
4019
|
-
n:
|
|
4020
|
-
d:
|
|
4053
|
+
s: bigint
|
|
4054
|
+
n: bigint
|
|
4055
|
+
d: bigint
|
|
4021
4056
|
}
|
|
4022
4057
|
|
|
4023
4058
|
export interface Complex {
|
|
@@ -4994,6 +5029,25 @@ export interface MathJsChain<TValue> {
|
|
|
4994
5029
|
this: MathJsChain<T>,
|
|
4995
5030
|
n?: number | BigNumber | MathCollection
|
|
4996
5031
|
): MathJsChain<T>
|
|
5032
|
+
ceil<U extends MathCollection>(
|
|
5033
|
+
this: MathJsChain<MathNumericType | U>,
|
|
5034
|
+
n: U
|
|
5035
|
+
): MathJsChain<U>
|
|
5036
|
+
ceil(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
|
|
5037
|
+
ceil<U extends MathCollection<Unit>>(
|
|
5038
|
+
this: MathJsChain<U>,
|
|
5039
|
+
unit: Unit
|
|
5040
|
+
): MathJsChain<U>
|
|
5041
|
+
ceil(
|
|
5042
|
+
this: MathJsChain<Unit>,
|
|
5043
|
+
n: number | BigNumber,
|
|
5044
|
+
unit: Unit
|
|
5045
|
+
): MathJsChain<Unit>
|
|
5046
|
+
ceil<U extends MathCollection<Unit>>(
|
|
5047
|
+
this: MathJsChain<U>,
|
|
5048
|
+
n: number | BigNumber,
|
|
5049
|
+
unit: Unit
|
|
5050
|
+
): MathJsChain<U>
|
|
4997
5051
|
|
|
4998
5052
|
/**
|
|
4999
5053
|
* Round a value towards zero. For matrices, the function is evaluated
|
|
@@ -5004,6 +5058,25 @@ export interface MathJsChain<TValue> {
|
|
|
5004
5058
|
this: MathJsChain<T>,
|
|
5005
5059
|
n?: number | BigNumber | MathCollection
|
|
5006
5060
|
): MathJsChain<T>
|
|
5061
|
+
fix<U extends MathCollection>(
|
|
5062
|
+
this: MathJsChain<MathNumericType | U>,
|
|
5063
|
+
n: U
|
|
5064
|
+
): MathJsChain<U>
|
|
5065
|
+
fix(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
|
|
5066
|
+
fix<U extends MathCollection<Unit>>(
|
|
5067
|
+
this: MathJsChain<U>,
|
|
5068
|
+
unit: Unit
|
|
5069
|
+
): MathJsChain<U>
|
|
5070
|
+
fix(
|
|
5071
|
+
this: MathJsChain<Unit>,
|
|
5072
|
+
n: number | BigNumber,
|
|
5073
|
+
unit: Unit
|
|
5074
|
+
): MathJsChain<Unit>
|
|
5075
|
+
fix<U extends MathCollection<Unit>>(
|
|
5076
|
+
this: MathJsChain<U>,
|
|
5077
|
+
n: number | BigNumber,
|
|
5078
|
+
unit: Unit
|
|
5079
|
+
): MathJsChain<U>
|
|
5007
5080
|
|
|
5008
5081
|
/**
|
|
5009
5082
|
* Round a value towards minus infinity. For matrices, the function is
|
|
@@ -5014,6 +5087,25 @@ export interface MathJsChain<TValue> {
|
|
|
5014
5087
|
this: MathJsChain<T>,
|
|
5015
5088
|
n?: number | BigNumber | MathCollection
|
|
5016
5089
|
): MathJsChain<T>
|
|
5090
|
+
floor<U extends MathCollection>(
|
|
5091
|
+
this: MathJsChain<MathNumericType | U>,
|
|
5092
|
+
n: U
|
|
5093
|
+
): MathJsChain<U>
|
|
5094
|
+
floor(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
|
|
5095
|
+
floor<U extends MathCollection<Unit>>(
|
|
5096
|
+
this: MathJsChain<U>,
|
|
5097
|
+
unit: Unit
|
|
5098
|
+
): MathJsChain<U>
|
|
5099
|
+
floor(
|
|
5100
|
+
this: MathJsChain<Unit>,
|
|
5101
|
+
n: number | BigNumber,
|
|
5102
|
+
unit: Unit
|
|
5103
|
+
): MathJsChain<Unit>
|
|
5104
|
+
floor<U extends MathCollection<Unit>>(
|
|
5105
|
+
this: MathJsChain<U>,
|
|
5106
|
+
n: number | BigNumber,
|
|
5107
|
+
unit: Unit
|
|
5108
|
+
): MathJsChain<U>
|
|
5017
5109
|
|
|
5018
5110
|
/**
|
|
5019
5111
|
* Round a value towards the nearest integer. For matrices, the function
|
|
@@ -5029,7 +5121,7 @@ export interface MathJsChain<TValue> {
|
|
|
5029
5121
|
n: U
|
|
5030
5122
|
): MathJsChain<U>
|
|
5031
5123
|
round(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
|
|
5032
|
-
round<U extends MathCollection
|
|
5124
|
+
round<U extends MathCollection<Unit>>(
|
|
5033
5125
|
this: MathJsChain<U>,
|
|
5034
5126
|
unit: Unit
|
|
5035
5127
|
): MathJsChain<U>
|
|
@@ -5038,7 +5130,7 @@ export interface MathJsChain<TValue> {
|
|
|
5038
5130
|
n: number | BigNumber,
|
|
5039
5131
|
unit: Unit
|
|
5040
5132
|
): MathJsChain<Unit>
|
|
5041
|
-
round<U extends MathCollection
|
|
5133
|
+
round<U extends MathCollection<Unit>>(
|
|
5042
5134
|
this: MathJsChain<U>,
|
|
5043
5135
|
n: number | BigNumber,
|
|
5044
5136
|
unit: Unit
|