mathjs 15.0.0 → 15.1.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 +22 -6
- package/README.md +1 -1
- 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/entry/dependenciesAny/dependenciesBernoulli.generated.js +25 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesConstantNode.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesEqual.generated.js +0 -2
- package/lib/cjs/entry/dependenciesAny/dependenciesIsBounded.generated.js +17 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesIsFinite.generated.js +21 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesIsInteger.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesUnitClass.generated.js +0 -2
- package/lib/cjs/entry/dependenciesAny/dependenciesZeta.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +21 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesBernoulli.generated.js +21 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesConstantNode.generated.js +2 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesIsBounded.generated.js +17 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesIsFinite.generated.js +21 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +2 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesZeta.generated.js +2 -0
- package/lib/cjs/entry/dependenciesNumber.generated.js +21 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +217 -212
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +82 -77
- package/lib/cjs/entry/pureFunctionsAny.generated.js +668 -652
- package/lib/cjs/entry/pureFunctionsNumber.generated.js +155 -140
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +6 -0
- package/lib/cjs/expression/embeddedDocs/function/combinatorics/stirlingS2.js +2 -2
- package/lib/cjs/expression/embeddedDocs/function/probability/bernoulli.js +14 -0
- package/lib/cjs/expression/embeddedDocs/function/utils/isBounded.js +14 -0
- package/lib/cjs/expression/embeddedDocs/function/utils/isFinite.js +14 -0
- package/lib/cjs/expression/embeddedDocs/function/utils/isNaN.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/utils/isNumeric.js +1 -1
- package/lib/cjs/expression/node/AccessorNode.js +36 -7
- package/lib/cjs/expression/node/ConstantNode.js +4 -4
- package/lib/cjs/expression/node/FunctionNode.js +20 -5
- package/lib/cjs/expression/parse.js +36 -12
- package/lib/cjs/factoriesAny.js +21 -0
- package/lib/cjs/factoriesNumber.js +23 -2
- package/lib/cjs/function/algebra/simplifyConstant.js +3 -2
- package/lib/cjs/function/arithmetic/nthRoots.js +5 -1
- package/lib/cjs/function/probability/bernoulli.js +108 -0
- package/lib/cjs/function/relational/equal.js +2 -3
- package/lib/cjs/function/special/zeta.js +3 -2
- package/lib/cjs/function/utils/isBounded.js +54 -0
- package/lib/cjs/function/utils/isFinite.js +50 -0
- package/lib/cjs/function/utils/isInteger.js +7 -15
- package/lib/cjs/function/utils/isNaN.js +1 -1
- package/lib/cjs/function/utils/isNumeric.js +1 -1
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/json/replacer.js +1 -1
- package/lib/cjs/plain/number/probability.js +2 -2
- package/lib/cjs/plain/number/trigonometry.js +1 -1
- package/lib/cjs/type/fraction/function/fraction.js +1 -1
- package/lib/cjs/type/matrix/SparseMatrix.js +24 -4
- package/lib/cjs/type/unit/Unit.js +12 -8
- package/lib/cjs/utils/number.js +7 -7
- package/lib/cjs/utils/optimizeCallback.js +13 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesBernoulli.generated.js +18 -0
- package/lib/esm/entry/dependenciesAny/dependenciesConstantNode.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesEqual.generated.js +0 -2
- package/lib/esm/entry/dependenciesAny/dependenciesIsBounded.generated.js +10 -0
- package/lib/esm/entry/dependenciesAny/dependenciesIsFinite.generated.js +14 -0
- package/lib/esm/entry/dependenciesAny/dependenciesIsInteger.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesUnitClass.generated.js +0 -2
- package/lib/esm/entry/dependenciesAny/dependenciesZeta.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny.generated.js +3 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesBernoulli.generated.js +14 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesConstantNode.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesIsBounded.generated.js +10 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesIsFinite.generated.js +14 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesZeta.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber.generated.js +3 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +219 -214
- package/lib/esm/entry/impureFunctionsNumber.generated.js +84 -79
- package/lib/esm/entry/pureFunctionsAny.generated.js +665 -649
- package/lib/esm/entry/pureFunctionsNumber.generated.js +154 -139
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +6 -0
- package/lib/esm/expression/embeddedDocs/function/combinatorics/stirlingS2.js +2 -2
- package/lib/esm/expression/embeddedDocs/function/probability/bernoulli.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/utils/isBounded.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/utils/isFinite.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/utils/isNaN.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/utils/isNumeric.js +1 -1
- package/lib/esm/expression/node/AccessorNode.js +36 -7
- package/lib/esm/expression/node/ConstantNode.js +4 -4
- package/lib/esm/expression/node/FunctionNode.js +20 -5
- package/lib/esm/expression/parse.js +36 -12
- package/lib/esm/factoriesAny.js +3 -0
- package/lib/esm/factoriesNumber.js +3 -0
- package/lib/esm/function/algebra/simplifyConstant.js +3 -2
- package/lib/esm/function/arithmetic/nthRoots.js +5 -1
- package/lib/esm/function/probability/bernoulli.js +102 -0
- package/lib/esm/function/relational/equal.js +2 -3
- package/lib/esm/function/special/zeta.js +3 -2
- package/lib/esm/function/utils/isBounded.js +48 -0
- package/lib/esm/function/utils/isFinite.js +44 -0
- package/lib/esm/function/utils/isInteger.js +7 -15
- package/lib/esm/function/utils/isNaN.js +1 -1
- package/lib/esm/function/utils/isNumeric.js +1 -1
- package/lib/esm/json/replacer.js +1 -1
- package/lib/esm/plain/number/probability.js +2 -2
- package/lib/esm/plain/number/trigonometry.js +1 -1
- package/lib/esm/type/fraction/function/fraction.js +1 -1
- package/lib/esm/type/matrix/SparseMatrix.js +24 -4
- package/lib/esm/type/unit/Unit.js +12 -8
- package/lib/esm/utils/number.js +7 -7
- package/lib/esm/utils/optimizeCallback.js +13 -1
- package/lib/esm/version.js +1 -1
- package/package.json +8 -8
- package/types/index.d.ts +535 -223
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createIsBounded = void 0;
|
|
7
|
+
var _factory = require("../../utils/factory.js");
|
|
8
|
+
const name = 'isBounded';
|
|
9
|
+
const dependencies = ['typed'];
|
|
10
|
+
const createIsBounded = exports.createIsBounded = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
|
11
|
+
let {
|
|
12
|
+
typed
|
|
13
|
+
} = _ref;
|
|
14
|
+
/**
|
|
15
|
+
* Test whether a value is bounded. For scalars, this test is equivalent
|
|
16
|
+
* to the isFinite finiteness test. On the other hand, a Matrix or Array
|
|
17
|
+
* is defined to be bounded if every entry is finite.
|
|
18
|
+
*
|
|
19
|
+
* Syntax:
|
|
20
|
+
*
|
|
21
|
+
* math.isBounded(x)
|
|
22
|
+
*
|
|
23
|
+
* Examples:
|
|
24
|
+
*
|
|
25
|
+
* math.isBounded(0) // returns true
|
|
26
|
+
* math.isBounded(NaN) // returns false
|
|
27
|
+
* math.isBounded(math.bignumber(Infinity)) // returns false
|
|
28
|
+
* math.isBounded(math.fraction(1,3)) // returns true
|
|
29
|
+
* math.isBounded(math.complex('2 - 4i')) // returns true
|
|
30
|
+
* math.isBounded(-10000000000000000n) // returns true
|
|
31
|
+
* math.isBounded(undefined) // returns false
|
|
32
|
+
* math.isBounded(null) // returns false
|
|
33
|
+
* math.isBounded([0.001, -3n, 0]) // returns true
|
|
34
|
+
* math.isBounded([2, -Infinity, -3]) // returns false
|
|
35
|
+
*
|
|
36
|
+
* See also:
|
|
37
|
+
*
|
|
38
|
+
* isFinite, isNumeric, isPositive, isNegative, isNaN
|
|
39
|
+
*
|
|
40
|
+
* @param {number | BigNumber | bigint | Complex | Fraction | Unit | Array | Matrix} x Value to be tested
|
|
41
|
+
* @return {boolean} Returns true when `x` is bounded.
|
|
42
|
+
*/
|
|
43
|
+
return typed(name, {
|
|
44
|
+
number: n => Number.isFinite(n),
|
|
45
|
+
'BigNumber | Complex': x => x.isFinite(),
|
|
46
|
+
'bigint | Fraction': () => true,
|
|
47
|
+
'null | undefined': () => false,
|
|
48
|
+
Unit: typed.referToSelf(self => x => self(x.value)),
|
|
49
|
+
'Array | Matrix': typed.referToSelf(self => A => {
|
|
50
|
+
if (!Array.isArray(A)) A = A.valueOf();
|
|
51
|
+
return A.every(entry => self(entry));
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createIsFinite = void 0;
|
|
7
|
+
var _factory = require("../../utils/factory.js");
|
|
8
|
+
const name = 'isFinite';
|
|
9
|
+
const dependencies = ['typed', 'isBounded', 'map'];
|
|
10
|
+
const createIsFinite = exports.createIsFinite = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
|
11
|
+
let {
|
|
12
|
+
typed,
|
|
13
|
+
isBounded,
|
|
14
|
+
map
|
|
15
|
+
} = _ref;
|
|
16
|
+
/**
|
|
17
|
+
* Test whether a value is finite.
|
|
18
|
+
*
|
|
19
|
+
* Operates elementwise on Array and Matrix values. To test if all entries
|
|
20
|
+
* of an Array or Matrix are finite, use isBounded.
|
|
21
|
+
*
|
|
22
|
+
* Syntax:
|
|
23
|
+
*
|
|
24
|
+
* math.isFinite(x)
|
|
25
|
+
*
|
|
26
|
+
* Examples:
|
|
27
|
+
*
|
|
28
|
+
* math.isFinite(0) // returns true
|
|
29
|
+
* math.isFinite(NaN) // returns false
|
|
30
|
+
* math.isFinite(math.bignumber(Infinity)) // returns false
|
|
31
|
+
* math.isFinite(math.fraction(1,3)) // returns true
|
|
32
|
+
* math.isFinite(math.complex('2 - 4i')) // returns true
|
|
33
|
+
* math.isFinite(-10000000000000000n) // returns true
|
|
34
|
+
* math.isFinite(undefined) // returns false
|
|
35
|
+
* math.isFinite(null) // returns false
|
|
36
|
+
* math.isFinite([0.001, -3n, 0]) // Array [true, true, true]
|
|
37
|
+
* math.isFinite([2, -Infinity, -3]) // Array [true, false, true]
|
|
38
|
+
*
|
|
39
|
+
* See also:
|
|
40
|
+
*
|
|
41
|
+
* isBounded isNumeric, isPositive, isNegative, isNaN
|
|
42
|
+
*
|
|
43
|
+
* @param {number | BigNumber | bigint | Complex | Fraction | Unit | Array | Matrix} x Value to be tested
|
|
44
|
+
* @return {boolean | Array | Matrix}
|
|
45
|
+
*/
|
|
46
|
+
return typed(name, {
|
|
47
|
+
'Array | Matrix': A => map(A, isBounded),
|
|
48
|
+
any: x => isBounded(x)
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -5,13 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createIsInteger = void 0;
|
|
7
7
|
var _collection = require("../../utils/collection.js");
|
|
8
|
-
var _number = require("../../utils/number.js");
|
|
9
8
|
var _factory = require("../../utils/factory.js");
|
|
10
9
|
const name = 'isInteger';
|
|
11
|
-
const dependencies = ['typed'];
|
|
10
|
+
const dependencies = ['typed', 'equal'];
|
|
12
11
|
const createIsInteger = exports.createIsInteger = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
|
13
12
|
let {
|
|
14
|
-
typed
|
|
13
|
+
typed,
|
|
14
|
+
equal
|
|
15
15
|
} = _ref;
|
|
16
16
|
/**
|
|
17
17
|
* Test whether a value is an integer number.
|
|
@@ -43,18 +43,10 @@ const createIsInteger = exports.createIsInteger = /* #__PURE__ */(0, _factory.fa
|
|
|
43
43
|
* Throws an error in case of an unknown data type.
|
|
44
44
|
*/
|
|
45
45
|
return typed(name, {
|
|
46
|
-
number:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return x.isInt();
|
|
51
|
-
},
|
|
52
|
-
bigint: function (x) {
|
|
53
|
-
return true;
|
|
54
|
-
},
|
|
55
|
-
Fraction: function (x) {
|
|
56
|
-
return x.d === 1n;
|
|
57
|
-
},
|
|
46
|
+
number: n => Number.isFinite(n) ? equal(n, Math.round(n)) : false,
|
|
47
|
+
BigNumber: b => b.isFinite() ? equal(b.round(), b) : false,
|
|
48
|
+
bigint: b => true,
|
|
49
|
+
Fraction: r => r.d === 1n,
|
|
58
50
|
'Array | Matrix': typed.referToSelf(self => x => (0, _collection.deepMap)(x, self))
|
|
59
51
|
});
|
|
60
52
|
});
|
|
@@ -36,7 +36,7 @@ const createIsNaN = exports.createIsNaN = /* #__PURE__ */(0, _factory.factory)(n
|
|
|
36
36
|
*
|
|
37
37
|
* See also:
|
|
38
38
|
*
|
|
39
|
-
* isNumeric, isNegative, isPositive, isZero, isInteger
|
|
39
|
+
* isNumeric, isNegative, isPositive, isZero, isInteger, isFinite, isBounded
|
|
40
40
|
*
|
|
41
41
|
* @param {number | BigNumber | bigint | Fraction | Unit | Array | Matrix} x Value to be tested
|
|
42
42
|
* @return {boolean} Returns true when `x` is NaN.
|
|
@@ -35,7 +35,7 @@ const createIsNumeric = exports.createIsNumeric = /* #__PURE__ */(0, _factory.fa
|
|
|
35
35
|
*
|
|
36
36
|
* See also:
|
|
37
37
|
*
|
|
38
|
-
* isZero, isPositive, isNegative, isInteger, hasNumericValue
|
|
38
|
+
* isZero, isPositive, isNegative, isInteger, hasNumericValue, isFinite, isBounded
|
|
39
39
|
*
|
|
40
40
|
* @param {*} x Value to be tested
|
|
41
41
|
* @return {boolean} Returns true when `x` is a `number`, `BigNumber`,
|
package/lib/cjs/header.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* It features real and complex numbers, units, matrices, a large set of
|
|
7
7
|
* mathematical functions, and a flexible expression parser.
|
|
8
8
|
*
|
|
9
|
-
* @version 15.
|
|
10
|
-
* @date 2025-
|
|
9
|
+
* @version 15.1.0
|
|
10
|
+
* @date 2025-11-05
|
|
11
11
|
*
|
|
12
12
|
* @license
|
|
13
13
|
* Copyright (C) 2013-2025 Jos de Jong <wjosdejong@gmail.com>
|
package/lib/cjs/json/replacer.js
CHANGED
|
@@ -22,7 +22,7 @@ const createReplacer = exports.createReplacer = /* #__PURE__ */(0, _factory.fact
|
|
|
22
22
|
*/
|
|
23
23
|
return function replacer(key, value) {
|
|
24
24
|
// the numeric values Infinitiy, -Infinity, and NaN cannot be serialized to JSON
|
|
25
|
-
if (typeof value === 'number' && (!isFinite(value) || isNaN(value))) {
|
|
25
|
+
if (typeof value === 'number' && (!Number.isFinite(value) || isNaN(value))) {
|
|
26
26
|
return {
|
|
27
27
|
mathjs: 'number',
|
|
28
28
|
value: String(value)
|
|
@@ -16,7 +16,7 @@ function gammaNumber(n) {
|
|
|
16
16
|
let x;
|
|
17
17
|
if ((0, _number.isInteger)(n)) {
|
|
18
18
|
if (n <= 0) {
|
|
19
|
-
return isFinite(n) ? Infinity : NaN;
|
|
19
|
+
return Number.isFinite(n) ? Infinity : NaN;
|
|
20
20
|
}
|
|
21
21
|
if (n > 171) {
|
|
22
22
|
return Infinity; // Will overflow
|
|
@@ -63,7 +63,7 @@ const lgammaSeries = exports.lgammaSeries = [1.000000000190015, 76.1800917294714
|
|
|
63
63
|
function lgammaNumber(n) {
|
|
64
64
|
if (n < 0) return NaN;
|
|
65
65
|
if (n === 0) return Infinity;
|
|
66
|
-
if (!isFinite(n)) return n;
|
|
66
|
+
if (!Number.isFinite(n)) return n;
|
|
67
67
|
if (n < 0.5) {
|
|
68
68
|
// Use Euler's reflection formula:
|
|
69
69
|
// gamma(z) = PI / (sin(PI * z) * gamma(1 - z))
|
|
@@ -44,7 +44,7 @@ function acotNumber(x) {
|
|
|
44
44
|
}
|
|
45
45
|
acotNumber.signature = n1;
|
|
46
46
|
function acothNumber(x) {
|
|
47
|
-
return isFinite(x) ? (Math.log((x + 1) / x) + Math.log(x / (x - 1))) / 2 : 0;
|
|
47
|
+
return Number.isFinite(x) ? (Math.log((x + 1) / x) + Math.log(x / (x - 1))) / 2 : 0;
|
|
48
48
|
}
|
|
49
49
|
acothNumber.signature = n1;
|
|
50
50
|
function acscNumber(x) {
|
|
@@ -52,7 +52,7 @@ const createFraction = exports.createFraction = /* #__PURE__ */(0, _factory.fact
|
|
|
52
52
|
*/
|
|
53
53
|
return typed('fraction', {
|
|
54
54
|
number: function (x) {
|
|
55
|
-
if (!isFinite(x) || isNaN(x)) {
|
|
55
|
+
if (!Number.isFinite(x) || isNaN(x)) {
|
|
56
56
|
throw new Error(x + ' cannot be represented as a fraction');
|
|
57
57
|
}
|
|
58
58
|
return new Fraction(x);
|
|
@@ -21,9 +21,27 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
|
|
|
21
21
|
Matrix
|
|
22
22
|
} = _ref;
|
|
23
23
|
/**
|
|
24
|
-
* Sparse Matrix implementation. This type implements
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* Sparse Matrix implementation. This type (currently) implements 2D
|
|
25
|
+
* matrices only via the format known as
|
|
26
|
+
* [Compressed Column Storage](https://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_column_(CSC_or_CCS)).
|
|
27
|
+
*
|
|
28
|
+
* The structure/invariants of the internal data should be:
|
|
29
|
+
* 1. _values is an array of the nonzero values in order from top to bottom
|
|
30
|
+
* (of each column), left to right.
|
|
31
|
+
* 2. _index is an array of row numbers, of the same length as and
|
|
32
|
+
* corresponding positionally to _values.
|
|
33
|
+
* 3. _ptr is an array of length one more than the number of columns. For j
|
|
34
|
+
* less than the number of columns, the "half-open" span of indices
|
|
35
|
+
* _ptr[j] to _ptr[j+1] (i.e. including _ptr[j] if it is less than
|
|
36
|
+
* _ptr[j+1], but never including _ptr[j+1]) are the indices in _values
|
|
37
|
+
* of the nonzero elements in column j. Note there are no nonzero elements
|
|
38
|
+
* in column j exactly when _ptr[j] === _ptr[j+1], and that the final
|
|
39
|
+
* entry in _ptr is always exactly the number of nonzero entries in the
|
|
40
|
+
* matrix.
|
|
41
|
+
* 4. _size is a length-2 array consisting of the number of rows followed by
|
|
42
|
+
* the number of columns.
|
|
43
|
+
* 5. _datatype, if set, is the mathjs typeOf value of all entries of the
|
|
44
|
+
* SparseMatrix.
|
|
27
45
|
* @class SparseMatrix
|
|
28
46
|
*/
|
|
29
47
|
function SparseMatrix(data, datatype) {
|
|
@@ -141,7 +159,9 @@ const createSparseMatrixClass = exports.createSparseMatrixClass = /* #__PURE__ *
|
|
|
141
159
|
} while (j < columns);
|
|
142
160
|
}
|
|
143
161
|
// store number of values in ptr
|
|
144
|
-
matrix._ptr.
|
|
162
|
+
while (matrix._ptr.length <= columns) {
|
|
163
|
+
matrix._ptr.push(matrix._index.length);
|
|
164
|
+
}
|
|
145
165
|
// size
|
|
146
166
|
matrix._size = [rows, columns];
|
|
147
167
|
}
|
|
@@ -13,7 +13,7 @@ var _string = require("../../utils/string.js");
|
|
|
13
13
|
var _object = require("../../utils/object.js");
|
|
14
14
|
var _constants = require("../../utils/bignumber/constants.js");
|
|
15
15
|
const name = 'Unit';
|
|
16
|
-
const dependencies = ['?on', 'config', 'addScalar', 'subtractScalar', 'multiplyScalar', 'divideScalar', 'pow', 'abs', 'fix', 'round', 'equal', 'isNumeric', 'format', '
|
|
16
|
+
const dependencies = ['?on', 'config', 'addScalar', 'subtractScalar', 'multiplyScalar', 'divideScalar', 'pow', 'abs', 'fix', 'round', 'equal', 'isNumeric', 'format', 'number', 'Complex', 'BigNumber', 'Fraction'];
|
|
17
17
|
const createUnitClass = exports.createUnitClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
|
18
18
|
let {
|
|
19
19
|
on,
|
|
@@ -29,13 +29,15 @@ const createUnitClass = exports.createUnitClass = /* #__PURE__ */(0, _factory.fa
|
|
|
29
29
|
equal,
|
|
30
30
|
isNumeric,
|
|
31
31
|
format,
|
|
32
|
-
toBest,
|
|
33
32
|
number,
|
|
34
33
|
Complex,
|
|
35
34
|
BigNumber,
|
|
36
35
|
Fraction
|
|
37
36
|
} = _ref;
|
|
38
37
|
const toNumber = number;
|
|
38
|
+
const fixPrefixDefault = false;
|
|
39
|
+
const skipAutomaticSimplificationDefault = true;
|
|
40
|
+
|
|
39
41
|
/**
|
|
40
42
|
* A unit can be constructed in the following ways:
|
|
41
43
|
*
|
|
@@ -62,13 +64,13 @@ const createUnitClass = exports.createUnitClass = /* #__PURE__ */(0, _factory.fa
|
|
|
62
64
|
if (!(value === null || value === undefined || isNumeric(value) || (0, _is.isComplex)(value))) {
|
|
63
65
|
throw new TypeError('First parameter in Unit constructor must be number, BigNumber, Fraction, Complex, or undefined');
|
|
64
66
|
}
|
|
65
|
-
this.fixPrefix =
|
|
67
|
+
this.fixPrefix = fixPrefixDefault; // if true, function format will not search for the
|
|
66
68
|
// best prefix but leave it as initially provided.
|
|
67
69
|
// fixPrefix is set true by the method Unit.to
|
|
68
70
|
|
|
69
71
|
// The justification behind this is that if the constructor is explicitly called,
|
|
70
72
|
// the caller wishes the units to be returned exactly as supplied.
|
|
71
|
-
this.skipAutomaticSimplification =
|
|
73
|
+
this.skipAutomaticSimplification = skipAutomaticSimplificationDefault;
|
|
72
74
|
if (valuelessUnit === undefined) {
|
|
73
75
|
this.units = [];
|
|
74
76
|
this.dimensions = BASE_DIMENSIONS.map(x => 0);
|
|
@@ -862,14 +864,15 @@ const createUnitClass = exports.createUnitClass = /* #__PURE__ */(0, _factory.fa
|
|
|
862
864
|
* Get a JSON representation of the unit
|
|
863
865
|
* @memberof Unit
|
|
864
866
|
* @returns {Object} Returns a JSON object structured as:
|
|
865
|
-
* `{"mathjs": "Unit", "value": 2, "unit": "cm", "fixPrefix": false}`
|
|
867
|
+
* `{"mathjs": "Unit", "value": 2, "unit": "cm", "fixPrefix": false, "skipSimp": true}`
|
|
866
868
|
*/
|
|
867
869
|
Unit.prototype.toJSON = function () {
|
|
868
870
|
return {
|
|
869
871
|
mathjs: 'Unit',
|
|
870
872
|
value: this._denormalize(this.value),
|
|
871
873
|
unit: this.units.length > 0 ? this.formatUnits() : null,
|
|
872
|
-
fixPrefix: this.fixPrefix
|
|
874
|
+
fixPrefix: this.fixPrefix,
|
|
875
|
+
skipSimp: this.skipAutomaticSimplification
|
|
873
876
|
};
|
|
874
877
|
};
|
|
875
878
|
|
|
@@ -881,9 +884,10 @@ const createUnitClass = exports.createUnitClass = /* #__PURE__ */(0, _factory.fa
|
|
|
881
884
|
* @return {Unit}
|
|
882
885
|
*/
|
|
883
886
|
Unit.fromJSON = function (json) {
|
|
884
|
-
var _json$unit;
|
|
887
|
+
var _json$unit, _json$fixPrefix, _json$skipSimp;
|
|
885
888
|
const unit = new Unit(json.value, (_json$unit = json.unit) !== null && _json$unit !== void 0 ? _json$unit : undefined);
|
|
886
|
-
unit.fixPrefix = json.fixPrefix
|
|
889
|
+
unit.fixPrefix = (_json$fixPrefix = json.fixPrefix) !== null && _json$fixPrefix !== void 0 ? _json$fixPrefix : fixPrefixDefault;
|
|
890
|
+
unit.skipAutomaticSimplification = (_json$skipSimp = json.skipSimp) !== null && _json$skipSimp !== void 0 ? _json$skipSimp : skipAutomaticSimplificationDefault;
|
|
887
891
|
return unit;
|
|
888
892
|
};
|
|
889
893
|
|
package/lib/cjs/utils/number.js
CHANGED
|
@@ -36,7 +36,7 @@ function isInteger(value) {
|
|
|
36
36
|
if (typeof value === 'boolean') {
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
|
-
return isFinite(value) ? value === Math.round(value) : false;
|
|
39
|
+
return Number.isFinite(value) ? value === Math.round(value) : false;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -128,7 +128,7 @@ const cbrt = exports.cbrt = Math.cbrt || function cbrt(x) {
|
|
|
128
128
|
if (negate) {
|
|
129
129
|
x = -x;
|
|
130
130
|
}
|
|
131
|
-
if (isFinite(x)) {
|
|
131
|
+
if (Number.isFinite(x)) {
|
|
132
132
|
result = Math.exp(Math.log(x) / 3);
|
|
133
133
|
// from https://en.wikipedia.org/wiki/Cube_root#Numerical_methods
|
|
134
134
|
result = (x / (result * result) + 2 * result) / 3;
|
|
@@ -404,7 +404,7 @@ function splitNumber(value) {
|
|
|
404
404
|
* @param {number} [precision] Optional number of significant figures to return.
|
|
405
405
|
*/
|
|
406
406
|
function toEngineering(value, precision) {
|
|
407
|
-
if (isNaN(value) || !isFinite(value)) {
|
|
407
|
+
if (isNaN(value) || !Number.isFinite(value)) {
|
|
408
408
|
return String(value);
|
|
409
409
|
}
|
|
410
410
|
const split = splitNumber(value);
|
|
@@ -453,7 +453,7 @@ function toEngineering(value, precision) {
|
|
|
453
453
|
* decimal point. null by default.
|
|
454
454
|
*/
|
|
455
455
|
function toFixed(value, precision) {
|
|
456
|
-
if (isNaN(value) || !isFinite(value)) {
|
|
456
|
+
if (isNaN(value) || !Number.isFinite(value)) {
|
|
457
457
|
return String(value);
|
|
458
458
|
}
|
|
459
459
|
const splitValue = splitNumber(value);
|
|
@@ -488,7 +488,7 @@ function toFixed(value, precision) {
|
|
|
488
488
|
* is used.
|
|
489
489
|
*/
|
|
490
490
|
function toExponential(value, precision) {
|
|
491
|
-
if (isNaN(value) || !isFinite(value)) {
|
|
491
|
+
if (isNaN(value) || !Number.isFinite(Number(value))) {
|
|
492
492
|
return String(value);
|
|
493
493
|
}
|
|
494
494
|
|
|
@@ -519,7 +519,7 @@ function toExponential(value, precision) {
|
|
|
519
519
|
* @return {string}
|
|
520
520
|
*/
|
|
521
521
|
function toPrecision(value, precision, options) {
|
|
522
|
-
if (isNaN(value) || !isFinite(value)) {
|
|
522
|
+
if (isNaN(value) || !Number.isFinite(value)) {
|
|
523
523
|
return String(value);
|
|
524
524
|
}
|
|
525
525
|
|
|
@@ -658,7 +658,7 @@ function nearlyEqual(a, b) {
|
|
|
658
658
|
if (isNaN(a) || isNaN(b)) {
|
|
659
659
|
return false;
|
|
660
660
|
}
|
|
661
|
-
if (!isFinite(a) || !isFinite(b)) {
|
|
661
|
+
if (!Number.isFinite(a) || !Number.isFinite(b)) {
|
|
662
662
|
return a === b;
|
|
663
663
|
}
|
|
664
664
|
if (a === b) {
|
|
@@ -23,7 +23,19 @@ function optimizeCallback(callback, array, name, isUnary) {
|
|
|
23
23
|
if (isUnary) {
|
|
24
24
|
numberOfArguments = 1;
|
|
25
25
|
} else {
|
|
26
|
-
const
|
|
26
|
+
const size = array.isMatrix ? array.size() : (0, _array.arraySize)(array);
|
|
27
|
+
|
|
28
|
+
// Check the size of the last dimension to see if the array/matrix is empty
|
|
29
|
+
const isEmpty = size.length ? size[size.length - 1] === 0 : true;
|
|
30
|
+
if (isEmpty) {
|
|
31
|
+
// don't optimize callbacks for empty arrays/matrix, as they will never be called
|
|
32
|
+
// and in fact will throw an exception when we try to access the first element below
|
|
33
|
+
return {
|
|
34
|
+
isUnary,
|
|
35
|
+
fn: callback
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const firstIndex = size.map(() => 0);
|
|
27
39
|
const firstValue = array.isMatrix ? array.get(firstIndex) : (0, _array.get)(array, firstIndex);
|
|
28
40
|
numberOfArguments = _findNumberOfArgumentsTyped(callback, firstValue, firstIndex, array);
|
|
29
41
|
}
|
package/lib/cjs/version.js
CHANGED
|
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.version = void 0;
|
|
7
|
-
const version = exports.version = '15.
|
|
7
|
+
const version = exports.version = '15.1.0';
|
|
8
8
|
// Note: This file is automatically generated when building math.js.
|
|
9
9
|
// Changes made in this file will be overwritten.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE IS AUTO-GENERATED
|
|
3
|
+
* DON'T MAKE CHANGES HERE
|
|
4
|
+
*/
|
|
5
|
+
import { BigNumberDependencies } from './dependenciesBigNumberClass.generated.js';
|
|
6
|
+
import { FractionDependencies } from './dependenciesFractionClass.generated.js';
|
|
7
|
+
import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
|
|
8
|
+
import { numberDependencies } from './dependenciesNumber.generated.js';
|
|
9
|
+
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
10
|
+
import { createBernoulli } from '../../factoriesAny.js';
|
|
11
|
+
export var bernoulliDependencies = {
|
|
12
|
+
BigNumberDependencies,
|
|
13
|
+
FractionDependencies,
|
|
14
|
+
isIntegerDependencies,
|
|
15
|
+
numberDependencies,
|
|
16
|
+
typedDependencies,
|
|
17
|
+
createBernoulli
|
|
18
|
+
};
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* DON'T MAKE CHANGES HERE
|
|
4
4
|
*/
|
|
5
5
|
import { NodeDependencies } from './dependenciesNode.generated.js';
|
|
6
|
+
import { isBoundedDependencies } from './dependenciesIsBounded.generated.js';
|
|
6
7
|
import { createConstantNode } from '../../factoriesAny.js';
|
|
7
8
|
export var ConstantNodeDependencies = {
|
|
8
9
|
NodeDependencies,
|
|
10
|
+
isBoundedDependencies,
|
|
9
11
|
createConstantNode
|
|
10
12
|
};
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { DenseMatrixDependencies } from './dependenciesDenseMatrixClass.generated.js';
|
|
6
6
|
import { SparseMatrixDependencies } from './dependenciesSparseMatrixClass.generated.js';
|
|
7
|
-
import { concatDependencies } from './dependenciesConcat.generated.js';
|
|
8
7
|
import { equalScalarDependencies } from './dependenciesEqualScalar.generated.js';
|
|
9
8
|
import { matrixDependencies } from './dependenciesMatrix.generated.js';
|
|
10
9
|
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
@@ -12,7 +11,6 @@ import { createEqual } from '../../factoriesAny.js';
|
|
|
12
11
|
export var equalDependencies = {
|
|
13
12
|
DenseMatrixDependencies,
|
|
14
13
|
SparseMatrixDependencies,
|
|
15
|
-
concatDependencies,
|
|
16
14
|
equalScalarDependencies,
|
|
17
15
|
matrixDependencies,
|
|
18
16
|
typedDependencies,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE IS AUTO-GENERATED
|
|
3
|
+
* DON'T MAKE CHANGES HERE
|
|
4
|
+
*/
|
|
5
|
+
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
6
|
+
import { createIsBounded } from '../../factoriesAny.js';
|
|
7
|
+
export var isBoundedDependencies = {
|
|
8
|
+
typedDependencies,
|
|
9
|
+
createIsBounded
|
|
10
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE IS AUTO-GENERATED
|
|
3
|
+
* DON'T MAKE CHANGES HERE
|
|
4
|
+
*/
|
|
5
|
+
import { isBoundedDependencies } from './dependenciesIsBounded.generated.js';
|
|
6
|
+
import { mapDependencies } from './dependenciesMap.generated.js';
|
|
7
|
+
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
8
|
+
import { createIsFinite } from '../../factoriesAny.js';
|
|
9
|
+
export var isFiniteDependencies = {
|
|
10
|
+
isBoundedDependencies,
|
|
11
|
+
mapDependencies,
|
|
12
|
+
typedDependencies,
|
|
13
|
+
createIsFinite
|
|
14
|
+
};
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* THIS FILE IS AUTO-GENERATED
|
|
3
3
|
* DON'T MAKE CHANGES HERE
|
|
4
4
|
*/
|
|
5
|
+
import { equalDependencies } from './dependenciesEqual.generated.js';
|
|
5
6
|
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
6
7
|
import { createIsInteger } from '../../factoriesAny.js';
|
|
7
8
|
export var isIntegerDependencies = {
|
|
9
|
+
equalDependencies,
|
|
8
10
|
typedDependencies,
|
|
9
11
|
createIsInteger
|
|
10
12
|
};
|
|
@@ -12,6 +12,7 @@ import { IndexNodeDependencies } from './dependenciesIndexNode.generated.js';
|
|
|
12
12
|
import { ObjectNodeDependencies } from './dependenciesObjectNode.generated.js';
|
|
13
13
|
import { OperatorNodeDependencies } from './dependenciesOperatorNode.generated.js';
|
|
14
14
|
import { SymbolNodeDependencies } from './dependenciesSymbolNode.generated.js';
|
|
15
|
+
import { isBoundedDependencies } from './dependenciesIsBounded.generated.js';
|
|
15
16
|
import { matrixDependencies } from './dependenciesMatrix.generated.js';
|
|
16
17
|
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
17
18
|
import { createSimplifyConstant } from '../../factoriesAny.js';
|
|
@@ -26,6 +27,7 @@ export var simplifyConstantDependencies = {
|
|
|
26
27
|
ObjectNodeDependencies,
|
|
27
28
|
OperatorNodeDependencies,
|
|
28
29
|
SymbolNodeDependencies,
|
|
30
|
+
isBoundedDependencies,
|
|
29
31
|
matrixDependencies,
|
|
30
32
|
typedDependencies,
|
|
31
33
|
createSimplifyConstant
|
|
@@ -17,7 +17,6 @@ import { numberDependencies } from './dependenciesNumber.generated.js';
|
|
|
17
17
|
import { powDependencies } from './dependenciesPow.generated.js';
|
|
18
18
|
import { roundDependencies } from './dependenciesRound.generated.js';
|
|
19
19
|
import { subtractScalarDependencies } from './dependenciesSubtractScalar.generated.js';
|
|
20
|
-
import { toBestDependencies } from './dependenciesToBest.generated.js';
|
|
21
20
|
import { createUnitClass } from '../../factoriesAny.js';
|
|
22
21
|
export var UnitDependencies = {
|
|
23
22
|
BigNumberDependencies,
|
|
@@ -35,6 +34,5 @@ export var UnitDependencies = {
|
|
|
35
34
|
powDependencies,
|
|
36
35
|
roundDependencies,
|
|
37
36
|
subtractScalarDependencies,
|
|
38
|
-
toBestDependencies,
|
|
39
37
|
createUnitClass
|
|
40
38
|
};
|
|
@@ -9,6 +9,7 @@ import { divideDependencies } from './dependenciesDivide.generated.js';
|
|
|
9
9
|
import { equalDependencies } from './dependenciesEqual.generated.js';
|
|
10
10
|
import { factorialDependencies } from './dependenciesFactorial.generated.js';
|
|
11
11
|
import { gammaDependencies } from './dependenciesGamma.generated.js';
|
|
12
|
+
import { isBoundedDependencies } from './dependenciesIsBounded.generated.js';
|
|
12
13
|
import { isNegativeDependencies } from './dependenciesIsNegative.generated.js';
|
|
13
14
|
import { multiplyDependencies } from './dependenciesMultiply.generated.js';
|
|
14
15
|
import { piDependencies } from './dependenciesPi.generated.js';
|
|
@@ -26,6 +27,7 @@ export var zetaDependencies = {
|
|
|
26
27
|
equalDependencies,
|
|
27
28
|
factorialDependencies,
|
|
28
29
|
gammaDependencies,
|
|
30
|
+
isBoundedDependencies,
|
|
29
31
|
isNegativeDependencies,
|
|
30
32
|
multiplyDependencies,
|
|
31
33
|
piDependencies,
|
|
@@ -27,6 +27,7 @@ export { atanhDependencies } from './dependenciesAny/dependenciesAtanh.generated
|
|
|
27
27
|
export { atomicMassDependencies } from './dependenciesAny/dependenciesAtomicMass.generated.js';
|
|
28
28
|
export { avogadroDependencies } from './dependenciesAny/dependenciesAvogadro.generated.js';
|
|
29
29
|
export { bellNumbersDependencies } from './dependenciesAny/dependenciesBellNumbers.generated.js';
|
|
30
|
+
export { bernoulliDependencies } from './dependenciesAny/dependenciesBernoulli.generated.js';
|
|
30
31
|
export { BigNumberDependencies } from './dependenciesAny/dependenciesBigNumberClass.generated.js';
|
|
31
32
|
export { bigintDependencies } from './dependenciesAny/dependenciesBigint.generated.js';
|
|
32
33
|
export { bignumberDependencies } from './dependenciesAny/dependenciesBignumber.generated.js';
|
|
@@ -158,6 +159,8 @@ export { intersectDependencies } from './dependenciesAny/dependenciesIntersect.g
|
|
|
158
159
|
export { invDependencies } from './dependenciesAny/dependenciesInv.generated.js';
|
|
159
160
|
export { inverseConductanceQuantumDependencies } from './dependenciesAny/dependenciesInverseConductanceQuantum.generated.js';
|
|
160
161
|
export { invmodDependencies } from './dependenciesAny/dependenciesInvmod.generated.js';
|
|
162
|
+
export { isBoundedDependencies } from './dependenciesAny/dependenciesIsBounded.generated.js';
|
|
163
|
+
export { isFiniteDependencies } from './dependenciesAny/dependenciesIsFinite.generated.js';
|
|
161
164
|
export { isIntegerDependencies } from './dependenciesAny/dependenciesIsInteger.generated.js';
|
|
162
165
|
export { isNaNDependencies } from './dependenciesAny/dependenciesIsNaN.generated.js';
|
|
163
166
|
export { isNegativeDependencies } from './dependenciesAny/dependenciesIsNegative.generated.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE IS AUTO-GENERATED
|
|
3
|
+
* DON'T MAKE CHANGES HERE
|
|
4
|
+
*/
|
|
5
|
+
import { isIntegerDependencies } from './dependenciesIsInteger.generated.js';
|
|
6
|
+
import { numberDependencies } from './dependenciesNumber.generated.js';
|
|
7
|
+
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
8
|
+
import { createBernoulli } from '../../factoriesNumber.js';
|
|
9
|
+
export var bernoulliDependencies = {
|
|
10
|
+
isIntegerDependencies,
|
|
11
|
+
numberDependencies,
|
|
12
|
+
typedDependencies,
|
|
13
|
+
createBernoulli
|
|
14
|
+
};
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* DON'T MAKE CHANGES HERE
|
|
4
4
|
*/
|
|
5
5
|
import { NodeDependencies } from './dependenciesNode.generated.js';
|
|
6
|
+
import { isBoundedDependencies } from './dependenciesIsBounded.generated.js';
|
|
6
7
|
import { createConstantNode } from '../../factoriesNumber.js';
|
|
7
8
|
export var ConstantNodeDependencies = {
|
|
8
9
|
NodeDependencies,
|
|
10
|
+
isBoundedDependencies,
|
|
9
11
|
createConstantNode
|
|
10
12
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE IS AUTO-GENERATED
|
|
3
|
+
* DON'T MAKE CHANGES HERE
|
|
4
|
+
*/
|
|
5
|
+
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
6
|
+
import { createIsBounded } from '../../factoriesNumber.js';
|
|
7
|
+
export var isBoundedDependencies = {
|
|
8
|
+
typedDependencies,
|
|
9
|
+
createIsBounded
|
|
10
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE IS AUTO-GENERATED
|
|
3
|
+
* DON'T MAKE CHANGES HERE
|
|
4
|
+
*/
|
|
5
|
+
import { isBoundedDependencies } from './dependenciesIsBounded.generated.js';
|
|
6
|
+
import { mapDependencies } from './dependenciesMap.generated.js';
|
|
7
|
+
import { typedDependencies } from './dependenciesTyped.generated.js';
|
|
8
|
+
import { createIsFinite } from '../../factoriesNumber.js';
|
|
9
|
+
export var isFiniteDependencies = {
|
|
10
|
+
isBoundedDependencies,
|
|
11
|
+
mapDependencies,
|
|
12
|
+
typedDependencies,
|
|
13
|
+
createIsFinite
|
|
14
|
+
};
|