mathjs 15.1.0 → 15.2.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 -0
- package/NOTICE +1 -1
- package/README.md +6 -6
- package/bin/cli.js +1 -1
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +3 -3
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/function/import.js +7 -0
- package/lib/cjs/core/function/typed.js +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesDen.generated.js +19 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesNum.generated.js +19 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +14 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +123 -121
- package/lib/cjs/entry/pureFunctionsAny.generated.js +344 -336
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +4 -0
- package/lib/cjs/expression/embeddedDocs/function/fraction/den.js +14 -0
- package/lib/cjs/expression/embeddedDocs/function/fraction/num.js +14 -0
- package/lib/cjs/expression/parse.js +26 -2
- package/lib/cjs/factoriesAny.js +15 -1
- package/lib/cjs/function/algebra/polynomialRoot.js +4 -0
- package/lib/cjs/function/arithmetic/add.js +8 -1
- package/lib/cjs/function/arithmetic/cbrt.js +7 -6
- package/lib/cjs/function/arithmetic/ceil.js +10 -2
- package/lib/cjs/function/arithmetic/exp.js +7 -5
- package/lib/cjs/function/arithmetic/expm1.js +6 -5
- package/lib/cjs/function/arithmetic/fix.js +10 -2
- package/lib/cjs/function/arithmetic/floor.js +10 -2
- package/lib/cjs/function/arithmetic/log.js +13 -0
- package/lib/cjs/function/arithmetic/mod.js +8 -2
- package/lib/cjs/function/arithmetic/nthRoot.js +9 -3
- package/lib/cjs/function/arithmetic/nthRoots.js +7 -10
- package/lib/cjs/function/fraction/den.js +60 -0
- package/lib/cjs/function/fraction/num.js +62 -0
- package/lib/cjs/function/matrix/map.js +6 -0
- package/lib/cjs/function/relational/compare.js +6 -0
- package/lib/cjs/function/relational/compareNatural.js +8 -2
- package/lib/cjs/function/relational/deepEqual.js +8 -3
- package/lib/cjs/function/relational/equal.js +15 -2
- package/lib/cjs/function/relational/unequal.js +14 -2
- package/lib/cjs/function/set/setDistinct.js +2 -1
- package/lib/cjs/function/string/format.js +9 -0
- package/lib/cjs/function/utils/isFinite.js +8 -1
- package/lib/cjs/function/utils/numeric.js +6 -0
- package/lib/cjs/header.js +3 -3
- package/lib/cjs/type/bigint.js +5 -0
- package/lib/cjs/type/boolean.js +6 -0
- package/lib/cjs/type/complex/function/complex.js +6 -0
- package/lib/cjs/type/fraction/function/fraction.js +8 -0
- package/lib/cjs/type/matrix/function/index.js +8 -0
- package/lib/cjs/type/matrix/function/matrix.js +6 -0
- package/lib/cjs/type/matrix/function/sparse.js +4 -0
- package/lib/cjs/type/string.js +4 -0
- package/lib/cjs/type/unit/Unit.js +7 -0
- package/lib/cjs/type/unit/function/unit.js +8 -0
- package/lib/cjs/utils/array.js +3 -0
- package/lib/cjs/utils/customs.js +39 -46
- package/lib/cjs/utils/map.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/function/import.js +7 -0
- package/lib/esm/core/function/typed.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesDen.generated.js +12 -0
- package/lib/esm/entry/dependenciesAny/dependenciesNum.generated.js +12 -0
- package/lib/esm/entry/dependenciesAny.generated.js +2 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +125 -123
- package/lib/esm/entry/pureFunctionsAny.generated.js +341 -333
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +4 -0
- package/lib/esm/expression/embeddedDocs/function/fraction/den.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/fraction/num.js +8 -0
- package/lib/esm/expression/parse.js +26 -2
- package/lib/esm/factoriesAny.js +3 -1
- package/lib/esm/function/algebra/polynomialRoot.js +4 -0
- package/lib/esm/function/arithmetic/add.js +8 -1
- package/lib/esm/function/arithmetic/cbrt.js +7 -6
- package/lib/esm/function/arithmetic/ceil.js +10 -2
- package/lib/esm/function/arithmetic/exp.js +7 -5
- package/lib/esm/function/arithmetic/expm1.js +6 -5
- package/lib/esm/function/arithmetic/fix.js +10 -2
- package/lib/esm/function/arithmetic/floor.js +10 -2
- package/lib/esm/function/arithmetic/log.js +13 -0
- package/lib/esm/function/arithmetic/mod.js +8 -2
- package/lib/esm/function/arithmetic/nthRoot.js +9 -3
- package/lib/esm/function/arithmetic/nthRoots.js +7 -10
- package/lib/esm/function/fraction/den.js +54 -0
- package/lib/esm/function/fraction/num.js +56 -0
- package/lib/esm/function/matrix/map.js +6 -0
- package/lib/esm/function/relational/compare.js +6 -0
- package/lib/esm/function/relational/compareNatural.js +8 -2
- package/lib/esm/function/relational/deepEqual.js +8 -3
- package/lib/esm/function/relational/equal.js +15 -2
- package/lib/esm/function/relational/unequal.js +14 -2
- package/lib/esm/function/set/setDistinct.js +2 -1
- package/lib/esm/function/string/format.js +9 -0
- package/lib/esm/function/utils/isFinite.js +8 -1
- package/lib/esm/function/utils/numeric.js +6 -0
- package/lib/esm/header.js +1 -1
- package/lib/esm/type/bigint.js +5 -0
- package/lib/esm/type/boolean.js +6 -0
- package/lib/esm/type/complex/function/complex.js +6 -0
- package/lib/esm/type/fraction/function/fraction.js +8 -0
- package/lib/esm/type/matrix/function/index.js +8 -0
- package/lib/esm/type/matrix/function/matrix.js +6 -0
- package/lib/esm/type/matrix/function/sparse.js +4 -0
- package/lib/esm/type/string.js +4 -0
- package/lib/esm/type/unit/Unit.js +7 -0
- package/lib/esm/type/unit/function/unit.js +8 -0
- package/lib/esm/utils/array.js +3 -0
- package/lib/esm/utils/customs.js +42 -56
- package/lib/esm/utils/map.js +3 -3
- package/lib/esm/version.js +1 -1
- package/package.json +14 -14
- package/types/index.d.ts +96 -15
|
@@ -94,6 +94,8 @@ var _subtract = require("./function/arithmetic/subtract.js");
|
|
|
94
94
|
var _unaryMinus = require("./function/arithmetic/unaryMinus.js");
|
|
95
95
|
var _unaryPlus = require("./function/arithmetic/unaryPlus.js");
|
|
96
96
|
var _xgcd = require("./function/arithmetic/xgcd.js");
|
|
97
|
+
var _num = require("./function/fraction/num.js");
|
|
98
|
+
var _den = require("./function/fraction/den.js");
|
|
97
99
|
var _bitAnd = require("./function/bitwise/bitAnd.js");
|
|
98
100
|
var _bitNot = require("./function/bitwise/bitNot.js");
|
|
99
101
|
var _bitOr = require("./function/bitwise/bitOr.js");
|
|
@@ -557,6 +559,8 @@ const embeddedDocs = exports.embeddedDocs = {
|
|
|
557
559
|
unaryPlus: _unaryPlus.unaryPlusDocs,
|
|
558
560
|
xgcd: _xgcd.xgcdDocs,
|
|
559
561
|
invmod: _invmod.invmodDocs,
|
|
562
|
+
num: _num.numDocs,
|
|
563
|
+
den: _den.denDocs,
|
|
560
564
|
// functions - bitwise
|
|
561
565
|
bitAnd: _bitAnd.bitAndDocs,
|
|
562
566
|
bitNot: _bitNot.bitNotDocs,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.denDocs = void 0;
|
|
7
|
+
const denDocs = exports.denDocs = {
|
|
8
|
+
name: 'den',
|
|
9
|
+
category: 'Fraction',
|
|
10
|
+
syntax: ['den(x)'],
|
|
11
|
+
description: 'Get the denominator of a fraction.',
|
|
12
|
+
examples: ['den(fraction(2, 3))', 'den(fraction(5, 8))'],
|
|
13
|
+
seealso: ['num', 'fraction']
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.numDocs = void 0;
|
|
7
|
+
const numDocs = exports.numDocs = {
|
|
8
|
+
name: 'num',
|
|
9
|
+
category: 'Fraction',
|
|
10
|
+
syntax: ['num(x)'],
|
|
11
|
+
description: 'Get the numerator of a fraction.',
|
|
12
|
+
examples: ['num(fraction(2, 3))', 'num(fraction(5, 8))'],
|
|
13
|
+
seealso: ['den', 'fraction']
|
|
14
|
+
};
|
|
@@ -68,6 +68,23 @@ const createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(n
|
|
|
68
68
|
*
|
|
69
69
|
* evaluate, compile
|
|
70
70
|
*
|
|
71
|
+
* History:
|
|
72
|
+
*
|
|
73
|
+
* v0.9 Created
|
|
74
|
+
* v0.13 Switched to one-based indices
|
|
75
|
+
* v0.14 Added `[1,2;3,4]` notation for matrices
|
|
76
|
+
* v0.18 Dropped the `function` keyword
|
|
77
|
+
* v0.20 Added ternary conditional
|
|
78
|
+
* v0.27 Allow multi-line expressions; allow functions that receive
|
|
79
|
+
* unevaluated parameters (`rawArgs`)
|
|
80
|
+
* v3 Add object notation; allow assignments internal to other
|
|
81
|
+
* expressions
|
|
82
|
+
* v7.3 Supported binary, octal, and hexadecimal notation
|
|
83
|
+
* v9.5 Support for calculations with percentages
|
|
84
|
+
* v12.4 Allow trailing commas in matrices
|
|
85
|
+
* v14.8 Add nullish coalescing operator
|
|
86
|
+
* v15.1 Add optional chaining operator
|
|
87
|
+
*
|
|
71
88
|
* @param {string | string[] | Matrix} expr Expression to be parsed
|
|
72
89
|
* @param {{nodes: Object<string, Node>}} [options] Available options:
|
|
73
90
|
* - `nodes` a set of custom nodes
|
|
@@ -897,8 +914,15 @@ const createParse = exports.createParse = /* #__PURE__ */(0, _factory.factory)(n
|
|
|
897
914
|
let node;
|
|
898
915
|
const params = [];
|
|
899
916
|
if (state.token === ':') {
|
|
900
|
-
|
|
901
|
-
|
|
917
|
+
if (state.conditionalLevel === state.nestingLevel) {
|
|
918
|
+
// we are in the midst of parsing a conditional operator, so not
|
|
919
|
+
// a range, but rather an empty true-expr, which is considered a
|
|
920
|
+
// syntax error
|
|
921
|
+
throw createSyntaxError(state, 'The true-expression of a conditional operator may not be empty');
|
|
922
|
+
} else {
|
|
923
|
+
// implicit start of range = 1 (one-based)
|
|
924
|
+
node = new ConstantNode(1);
|
|
925
|
+
}
|
|
902
926
|
} else {
|
|
903
927
|
// explicit start
|
|
904
928
|
node = parseAddSubtract(state);
|
package/lib/cjs/factoriesAny.js
CHANGED
|
@@ -495,6 +495,12 @@ Object.defineProperty(exports, "createDeepEqual", {
|
|
|
495
495
|
return _deepEqual.createDeepEqual;
|
|
496
496
|
}
|
|
497
497
|
});
|
|
498
|
+
Object.defineProperty(exports, "createDen", {
|
|
499
|
+
enumerable: true,
|
|
500
|
+
get: function () {
|
|
501
|
+
return _den.createDen;
|
|
502
|
+
}
|
|
503
|
+
});
|
|
498
504
|
Object.defineProperty(exports, "createDenseMatrixClass", {
|
|
499
505
|
enumerable: true,
|
|
500
506
|
get: function () {
|
|
@@ -1371,6 +1377,12 @@ Object.defineProperty(exports, "createNullishTransform", {
|
|
|
1371
1377
|
return _nullishTransform.createNullishTransform;
|
|
1372
1378
|
}
|
|
1373
1379
|
});
|
|
1380
|
+
Object.defineProperty(exports, "createNum", {
|
|
1381
|
+
enumerable: true,
|
|
1382
|
+
get: function () {
|
|
1383
|
+
return _num.createNum;
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1374
1386
|
Object.defineProperty(exports, "createNumber", {
|
|
1375
1387
|
enumerable: true,
|
|
1376
1388
|
get: function () {
|
|
@@ -2517,4 +2529,6 @@ var _andTransform = require("./expression/transform/and.transform.js");
|
|
|
2517
2529
|
var _orTransform = require("./expression/transform/or.transform.js");
|
|
2518
2530
|
var _nullishTransform = require("./expression/transform/nullish.transform.js");
|
|
2519
2531
|
var _bitAndTransform = require("./expression/transform/bitAnd.transform.js");
|
|
2520
|
-
var _bitOrTransform = require("./expression/transform/bitOr.transform.js");
|
|
2532
|
+
var _bitOrTransform = require("./expression/transform/bitOr.transform.js");
|
|
2533
|
+
var _num = require("./function/fraction/num.js");
|
|
2534
|
+
var _den = require("./function/fraction/den.js");
|
|
@@ -52,6 +52,10 @@ const createPolynomialRoot = exports.createPolynomialRoot = /* #__PURE__ */(0, _
|
|
|
52
52
|
* See also:
|
|
53
53
|
* cbrt, sqrt
|
|
54
54
|
*
|
|
55
|
+
* History:
|
|
56
|
+
*
|
|
57
|
+
* v11.4 Created
|
|
58
|
+
*
|
|
55
59
|
* @param {... number | Complex} coeffs
|
|
56
60
|
* The coefficients of the polynomial, starting with with the constant coefficent, followed
|
|
57
61
|
* by the linear coefficient and subsequent coefficients of increasing powers.
|
|
@@ -59,7 +59,7 @@ const createAdd = exports.createAdd = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
59
59
|
*
|
|
60
60
|
* const c = math.unit('5 cm')
|
|
61
61
|
* const d = math.unit('2.1 mm')
|
|
62
|
-
* math.add(c, d) // returns Unit
|
|
62
|
+
* math.add(c, d) // returns Unit 5.21 cm
|
|
63
63
|
*
|
|
64
64
|
* math.add("2.3", "4") // returns number 6.3
|
|
65
65
|
*
|
|
@@ -67,6 +67,13 @@ const createAdd = exports.createAdd = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
67
67
|
*
|
|
68
68
|
* subtract, sum
|
|
69
69
|
*
|
|
70
|
+
* History:
|
|
71
|
+
*
|
|
72
|
+
* v13 Handle bigint arguments
|
|
73
|
+
* v11.6 Support matrix broadcasting
|
|
74
|
+
* v3.8 Allow more than two arguments
|
|
75
|
+
* v0.0.2 Created
|
|
76
|
+
*
|
|
70
77
|
* @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} x First value to add
|
|
71
78
|
* @param {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} y Second value to add
|
|
72
79
|
* @return {number | BigNumber | bigint | Fraction | Complex | Unit | Array | Matrix} Sum of `x` and `y`
|
|
@@ -41,17 +41,18 @@ const createCbrt = exports.createCbrt = /* #__PURE__ */(0, _factory.factory)(nam
|
|
|
41
41
|
* math.map([27, 64, 125], x => math.cbrt(x)) // returns [3, 4, 5]
|
|
42
42
|
*
|
|
43
43
|
* const x = math.complex('8i')
|
|
44
|
-
* math.cbrt(x) // returns
|
|
45
|
-
* math.cbrt(x, true)
|
|
46
|
-
*
|
|
47
|
-
* // -1.7320508075689 + i
|
|
48
|
-
* // -2i
|
|
49
|
-
* // ]
|
|
44
|
+
* math.cbrt(x) // returns 1.7320508075689 + i ...
|
|
45
|
+
* math.cbrt(x, true)
|
|
46
|
+
* // Complex Matrix ["1.7320508075689+i", "-1.7320508075689+i", "-2i"]
|
|
50
47
|
*
|
|
51
48
|
* See also:
|
|
52
49
|
*
|
|
53
50
|
* square, sqrt, cube
|
|
54
51
|
*
|
|
52
|
+
* History:
|
|
53
|
+
*
|
|
54
|
+
* v2.3 Created
|
|
55
|
+
*
|
|
55
56
|
* @param {number | BigNumber | Complex | Unit} x
|
|
56
57
|
* Value for which to calculate the cubic root.
|
|
57
58
|
* @param {boolean} [allRoots] Optional, false by default. Only applicable
|
|
@@ -106,13 +106,13 @@ const createCeil = exports.createCeil = /* #__PURE__ */(0, _factory.factory)(nam
|
|
|
106
106
|
* math.ceil(-4.782, 2) // returns number -4.78
|
|
107
107
|
*
|
|
108
108
|
* const c = math.complex(3.24, -2.71)
|
|
109
|
-
* math.ceil(c) // returns Complex 4 - 2i
|
|
109
|
+
* math.ceil(c) // returns Complex 4 - 2i ...
|
|
110
110
|
* math.ceil(c, 1) // returns Complex 3.3 - 2.7i
|
|
111
111
|
*
|
|
112
112
|
* const unit = math.unit('3.241 cm')
|
|
113
113
|
* const cm = math.unit('cm')
|
|
114
114
|
* const mm = math.unit('mm')
|
|
115
|
-
* math.ceil(unit, 1, cm) // returns Unit 3.3 cm
|
|
115
|
+
* math.ceil(unit, 1, cm) // returns Unit 3.3 cm ...
|
|
116
116
|
* math.ceil(unit, 1, mm) // returns Unit 32.5 mm
|
|
117
117
|
*
|
|
118
118
|
* math.ceil([3.2, 3.8, -4.7]) // returns Array [4, 4, -4]
|
|
@@ -122,6 +122,14 @@ const createCeil = exports.createCeil = /* #__PURE__ */(0, _factory.factory)(nam
|
|
|
122
122
|
*
|
|
123
123
|
* floor, fix, round
|
|
124
124
|
*
|
|
125
|
+
* History:
|
|
126
|
+
*
|
|
127
|
+
* v14 Handle Units
|
|
128
|
+
* v7.4 Allow second "precision" argument
|
|
129
|
+
* v5.7 Support tolerance for round-off errors
|
|
130
|
+
* v2 Handle Fractions
|
|
131
|
+
* v0.1 Created
|
|
132
|
+
*
|
|
125
133
|
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Value to be rounded
|
|
126
134
|
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
|
127
135
|
* @param {Unit} [valuelessUnit] A valueless unit
|
|
@@ -29,16 +29,18 @@ const createExp = exports.createExp = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
29
29
|
* math.log(math.exp(2)) // returns number 2
|
|
30
30
|
*
|
|
31
31
|
* math.map([1, 2, 3], math.exp)
|
|
32
|
-
* // returns
|
|
33
|
-
* // 2.718281828459045,
|
|
34
|
-
* // 7.3890560989306495,
|
|
35
|
-
* // 20.085536923187668
|
|
36
|
-
* // ]
|
|
32
|
+
* // returns [2.718281828459045, 7.3890560989306495, 20.085536923187668]
|
|
37
33
|
*
|
|
38
34
|
* See also:
|
|
39
35
|
*
|
|
40
36
|
* expm1, expm, log, pow
|
|
41
37
|
*
|
|
38
|
+
* History:
|
|
39
|
+
*
|
|
40
|
+
* v11 Don't apply elementwise, avoid confusion with matrix exponential
|
|
41
|
+
* v0.20 Handle BigNumbers
|
|
42
|
+
* v0.0.2 Created
|
|
43
|
+
*
|
|
42
44
|
* @param {number | BigNumber | Complex} x A number to exponentiate
|
|
43
45
|
* @return {number | BigNumber | Complex} Exponential of `x`
|
|
44
46
|
*/
|
|
@@ -33,16 +33,17 @@ const createExpm1 = exports.createExpm1 = /* #__PURE__ */(0, _factory.factory)(n
|
|
|
33
33
|
* math.log(math.expm1(2) + 1) // returns number 2
|
|
34
34
|
*
|
|
35
35
|
* math.map([1, 2, 3], math.expm1)
|
|
36
|
-
* // returns
|
|
37
|
-
* // 1.718281828459045,
|
|
38
|
-
* // 6.3890560989306495,
|
|
39
|
-
* // 19.085536923187668
|
|
40
|
-
* // ]
|
|
36
|
+
* // returns [1.718281828459045, 6.3890560989306495, 19.085536923187668]
|
|
41
37
|
*
|
|
42
38
|
* See also:
|
|
43
39
|
*
|
|
44
40
|
* exp, expm, log, pow
|
|
45
41
|
*
|
|
42
|
+
* History:
|
|
43
|
+
*
|
|
44
|
+
* v11 Don't apply elementwise, avoids confusion with matrix exponential
|
|
45
|
+
* v4.2 Created
|
|
46
|
+
*
|
|
46
47
|
* @param {number | BigNumber | Complex} x The number to exponentiate
|
|
47
48
|
* @return {number | BigNumber | Complex} Exponential of `x`, minus one
|
|
48
49
|
*/
|
|
@@ -72,13 +72,13 @@ const createFix = exports.createFix = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
72
72
|
* math.fix(-4.17, 1) // returns number -4.1
|
|
73
73
|
*
|
|
74
74
|
* const c = math.complex(3.22, -2.78)
|
|
75
|
-
* math.fix(c) // returns Complex 3 - 2i
|
|
75
|
+
* math.fix(c) // returns Complex 3 - 2i ...
|
|
76
76
|
* math.fix(c, 1) // returns Complex 3.2 -2.7i
|
|
77
77
|
*
|
|
78
78
|
* const unit = math.unit('3.241 cm')
|
|
79
79
|
* const cm = math.unit('cm')
|
|
80
80
|
* const mm = math.unit('mm')
|
|
81
|
-
* math.fix(unit, 1, cm) // returns Unit 3.2 cm
|
|
81
|
+
* math.fix(unit, 1, cm) // returns Unit 3.2 cm ...
|
|
82
82
|
* math.fix(unit, 1, mm) // returns Unit 32.4 mm
|
|
83
83
|
*
|
|
84
84
|
* math.fix([3.2, 3.8, -4.7]) // returns Array [3, 3, -4]
|
|
@@ -88,6 +88,14 @@ const createFix = exports.createFix = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
88
88
|
*
|
|
89
89
|
* ceil, floor, round
|
|
90
90
|
*
|
|
91
|
+
* History:
|
|
92
|
+
*
|
|
93
|
+
* v14 Handle Units
|
|
94
|
+
* v7.4 Allow second "precision" argument
|
|
95
|
+
* v5.7 Support tolerance for round-off errors
|
|
96
|
+
* v2 Handle Fractions
|
|
97
|
+
* v0.1 Created
|
|
98
|
+
*
|
|
91
99
|
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Value to be rounded
|
|
92
100
|
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
|
93
101
|
* @param {Unit} [valuelessUnit] A valueless unit
|
|
@@ -112,13 +112,13 @@ const createFloor = exports.createFloor = /* #__PURE__ */(0, _factory.factory)(n
|
|
|
112
112
|
* math.floor(-4.782, 2) // returns number -4.79
|
|
113
113
|
*
|
|
114
114
|
* const c = math.complex(3.24, -2.71)
|
|
115
|
-
* math.floor(c) // returns Complex 3 - 3i
|
|
115
|
+
* math.floor(c) // returns Complex 3 - 3i ...
|
|
116
116
|
* math.floor(c, 1) // returns Complex 3.2 -2.8i
|
|
117
117
|
*
|
|
118
118
|
* const unit = math.unit('3.241 cm')
|
|
119
119
|
* const cm = math.unit('cm')
|
|
120
120
|
* const mm = math.unit('mm')
|
|
121
|
-
* math.floor(unit, 1, cm) // returns Unit 3.2 cm
|
|
121
|
+
* math.floor(unit, 1, cm) // returns Unit 3.2 cm ...
|
|
122
122
|
* math.floor(unit, 1, mm) // returns Unit 32.4 mm
|
|
123
123
|
*
|
|
124
124
|
* math.floor([3.2, 3.8, -4.7]) // returns Array [3, 3, -5]
|
|
@@ -132,6 +132,14 @@ const createFloor = exports.createFloor = /* #__PURE__ */(0, _factory.factory)(n
|
|
|
132
132
|
*
|
|
133
133
|
* ceil, fix, round
|
|
134
134
|
*
|
|
135
|
+
* History:
|
|
136
|
+
*
|
|
137
|
+
* v14 Handle Units
|
|
138
|
+
* v7.4 Allow second "precision" argument
|
|
139
|
+
* v5.7 Support tolerance for round-off errors
|
|
140
|
+
* v2 Handle Fractions
|
|
141
|
+
* v0.1 Created
|
|
142
|
+
*
|
|
135
143
|
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Value to be rounded
|
|
136
144
|
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
|
137
145
|
* @param {Unit} [valuelessUnit] A valueless unit
|
|
@@ -45,6 +45,19 @@ const createLog = exports.createLog = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
45
45
|
*
|
|
46
46
|
* exp, log2, log10, log1p
|
|
47
47
|
*
|
|
48
|
+
* History:
|
|
49
|
+
*
|
|
50
|
+
* v0.0.2 Created
|
|
51
|
+
* v0.2 Add optional base argument
|
|
52
|
+
* v0.3 Handle Array input
|
|
53
|
+
* v0.5 Handle Matrix input
|
|
54
|
+
* v0.16 Handle BigNumber input
|
|
55
|
+
* v0.21 Support negative BigNumbers
|
|
56
|
+
* v11 Drop Array/Matrix support in favor of explicit map of
|
|
57
|
+
* the scalar log function, to avoid confusion with the log
|
|
58
|
+
* of a matrix
|
|
59
|
+
* v14 Allow value and base to be Fractions, when the log is rational
|
|
60
|
+
*
|
|
48
61
|
* @param {number | BigNumber | Fraction | Complex} x
|
|
49
62
|
* Value for which to calculate the logarithm.
|
|
50
63
|
* @param {number | BigNumber | Fraction | Complex} [base=e]
|
|
@@ -82,14 +82,20 @@ const createMod = exports.createMod = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
82
82
|
* function isOdd(x) {
|
|
83
83
|
* return math.mod(x, 2) != 0
|
|
84
84
|
* }
|
|
85
|
-
*
|
|
86
|
-
* isOdd(2) // returns false
|
|
85
|
+
* isOdd(2) // returns false...
|
|
87
86
|
* isOdd(3) // returns true
|
|
88
87
|
*
|
|
89
88
|
* See also:
|
|
90
89
|
*
|
|
91
90
|
* divide
|
|
92
91
|
*
|
|
92
|
+
* History:
|
|
93
|
+
*
|
|
94
|
+
* v13 Handle bigints
|
|
95
|
+
* v11.6 Support matrix broadcasting
|
|
96
|
+
* v2 Handle Fractions
|
|
97
|
+
* v0.2 Created
|
|
98
|
+
*
|
|
93
99
|
* @param {number | BigNumber | bigint | Fraction | Array | Matrix} x Dividend
|
|
94
100
|
* @param {number | BigNumber | bigint | Fraction | Array | Matrix} y Divisor
|
|
95
101
|
* @return {number | BigNumber | bigint | Fraction | Array | Matrix} Returns the remainder of `x` divided by `y`.
|
|
@@ -58,14 +58,20 @@ const createNthRoot = exports.createNthRoot = /* #__PURE__ */(0, _factory.factor
|
|
|
58
58
|
*
|
|
59
59
|
* Examples:
|
|
60
60
|
*
|
|
61
|
-
* math.nthRoot(9, 2) // returns 3
|
|
62
|
-
* math.sqrt(9) // returns 3
|
|
63
|
-
* math.nthRoot(64, 3) // returns 4
|
|
61
|
+
* math.nthRoot(9, 2) // returns 3
|
|
62
|
+
* math.sqrt(9) // returns 3
|
|
63
|
+
* math.nthRoot(64, 3) // returns 4
|
|
64
64
|
*
|
|
65
65
|
* See also:
|
|
66
66
|
*
|
|
67
67
|
* sqrt, pow
|
|
68
68
|
*
|
|
69
|
+
* History:
|
|
70
|
+
*
|
|
71
|
+
* v11.6 Support matrix broadcasting
|
|
72
|
+
* v2 Handle Complex
|
|
73
|
+
* v1.1 Created
|
|
74
|
+
*
|
|
69
75
|
* @param {number | BigNumber | Array | Matrix | Complex} a
|
|
70
76
|
* Value for which to calculate the nth root
|
|
71
77
|
* @param {number | BigNumber} [root=2] The root.
|
|
@@ -92,22 +92,19 @@ const createNthRoots = exports.createNthRoots = /* #__PURE__ */(0, _factory.fact
|
|
|
92
92
|
*
|
|
93
93
|
* Examples:
|
|
94
94
|
*
|
|
95
|
-
* math.nthRoots(1)
|
|
96
|
-
*
|
|
97
|
-
* // {re: 1, im: 0},
|
|
98
|
-
* // {re: -1, im: 0}
|
|
99
|
-
* // ]
|
|
95
|
+
* math.nthRoots(1) // returns [ {re: 1, im: 0}, {re: -1, im: 0} ]
|
|
96
|
+
*
|
|
100
97
|
* math.nthRoots(1, 3)
|
|
101
|
-
* //
|
|
102
|
-
* // { re: 1, im: 0 },
|
|
103
|
-
* // { re: -0.4999999999999998, im: 0.8660254037844387 },
|
|
104
|
-
* // { re: -0.5000000000000004, im: -0.8660254037844385 }
|
|
105
|
-
* // ]
|
|
98
|
+
* // Complex [1, "-0.5+0.866025403784439i", "-0.5-0.866025403784439i"]
|
|
106
99
|
*
|
|
107
100
|
* See also:
|
|
108
101
|
*
|
|
109
102
|
* nthRoot, pow, sqrt
|
|
110
103
|
*
|
|
104
|
+
* History:
|
|
105
|
+
*
|
|
106
|
+
* v1.1 Created
|
|
107
|
+
*
|
|
111
108
|
* @param {number | BigNumber | Fraction | Complex} x Number to be rounded
|
|
112
109
|
* @param {number} [root=2] Optional root, default value is 2
|
|
113
110
|
* @return {number | BigNumber | Fraction | Complex} Returns the nth roots
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDen = void 0;
|
|
7
|
+
var _factory = require("../../utils/factory.js");
|
|
8
|
+
var _collection = require("../../utils/collection.js");
|
|
9
|
+
const name = 'den';
|
|
10
|
+
const dependencies = ['typed', 'fraction'];
|
|
11
|
+
const createDen = exports.createDen = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
|
12
|
+
let {
|
|
13
|
+
typed,
|
|
14
|
+
fraction
|
|
15
|
+
} = _ref;
|
|
16
|
+
/**
|
|
17
|
+
* Get the denominator of a fraction.
|
|
18
|
+
* For a fraction `a/b`, the function returns `b`.
|
|
19
|
+
*
|
|
20
|
+
* The result is always in lowest terms. For example, `den(fraction(8, 6))`
|
|
21
|
+
* returns `3n` because 8/6 simplifies to 4/3.
|
|
22
|
+
*
|
|
23
|
+
* For negative fractions like `-a/b` or `a/-b`, the denominator is
|
|
24
|
+
* always returned as a positive bigint. The sign is stored in the
|
|
25
|
+
* numerator. So `den(fraction(-2, 3))` and `den(fraction(2, -3))`
|
|
26
|
+
* both return `3n`.
|
|
27
|
+
*
|
|
28
|
+
* For matrices, the function is evaluated element wise.
|
|
29
|
+
*
|
|
30
|
+
* Syntax:
|
|
31
|
+
*
|
|
32
|
+
* math.den(x)
|
|
33
|
+
*
|
|
34
|
+
* Examples:
|
|
35
|
+
*
|
|
36
|
+
* math.den(math.fraction(2, 3)) // returns 3n
|
|
37
|
+
* math.den(math.fraction(8, 6)) // returns 3n
|
|
38
|
+
* math.den(math.fraction('5/8')) // returns 8n
|
|
39
|
+
* math.den(math.fraction(-2, 3)) // returns 3n
|
|
40
|
+
* math.den(math.fraction(2, -3)) // returns 3n
|
|
41
|
+
* math.den(math.bignumber('0.5')) // returns 2n
|
|
42
|
+
*
|
|
43
|
+
* See also:
|
|
44
|
+
*
|
|
45
|
+
* num, fraction
|
|
46
|
+
*
|
|
47
|
+
* History:
|
|
48
|
+
*
|
|
49
|
+
* v15.2.0 Created
|
|
50
|
+
*
|
|
51
|
+
* @param {Fraction | BigNumber | Array | Matrix} x
|
|
52
|
+
* A fraction, BigNumber, or array with fractions
|
|
53
|
+
* @return {bigint | Array | Matrix} The denominator of x (in lowest terms)
|
|
54
|
+
*/
|
|
55
|
+
return typed(name, {
|
|
56
|
+
Fraction: x => x.d,
|
|
57
|
+
BigNumber: x => fraction(x).d,
|
|
58
|
+
'Array | Matrix': typed.referToSelf(self => x => (0, _collection.deepMap)(x, self))
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createNum = void 0;
|
|
7
|
+
var _factory = require("../../utils/factory.js");
|
|
8
|
+
var _collection = require("../../utils/collection.js");
|
|
9
|
+
const name = 'num';
|
|
10
|
+
const dependencies = ['typed', 'fraction'];
|
|
11
|
+
const createNum = exports.createNum = /* #__PURE__ */(0, _factory.factory)(name, dependencies, _ref => {
|
|
12
|
+
let {
|
|
13
|
+
typed,
|
|
14
|
+
fraction
|
|
15
|
+
} = _ref;
|
|
16
|
+
/**
|
|
17
|
+
* Get the numerator of a fraction.
|
|
18
|
+
* For a fraction `a/b`, the function returns `a`.
|
|
19
|
+
*
|
|
20
|
+
* The result is always in lowest terms. For example, `num(fraction(8, 6))`
|
|
21
|
+
* returns `4n` because 8/6 simplifies to 4/3.
|
|
22
|
+
*
|
|
23
|
+
* For negative fractions like `-a/b` or `a/-b`, the sign is always
|
|
24
|
+
* included in the numerator. Both forms are normalized internally, so
|
|
25
|
+
* `num(fraction(-2, 3))` and `num(fraction(2, -3))` both return `-2`.
|
|
26
|
+
*
|
|
27
|
+
* For matrices, the function is evaluated element wise.
|
|
28
|
+
*
|
|
29
|
+
* Syntax:
|
|
30
|
+
*
|
|
31
|
+
* math.num(x)
|
|
32
|
+
*
|
|
33
|
+
* Examples:
|
|
34
|
+
*
|
|
35
|
+
* math.num(math.fraction(2, 3)) // returns 2n
|
|
36
|
+
* math.num(math.fraction(8, 6)) // returns 4n
|
|
37
|
+
* math.num(math.fraction('5/8')) // returns 5n
|
|
38
|
+
* math.num(math.fraction(-2, 3)) // returns -2n
|
|
39
|
+
* math.num(math.fraction(2, -3)) // returns -2n
|
|
40
|
+
* math.num(math.bignumber('0.5')) // returns 1n
|
|
41
|
+
*
|
|
42
|
+
* See also:
|
|
43
|
+
*
|
|
44
|
+
* den, fraction
|
|
45
|
+
*
|
|
46
|
+
* History:
|
|
47
|
+
*
|
|
48
|
+
* v15.2.0 Created
|
|
49
|
+
*
|
|
50
|
+
* @param {Fraction | BigNumber | Array | Matrix} x
|
|
51
|
+
* A fraction, BigNumber, or array with fractions
|
|
52
|
+
* @return {bigint | Array | Matrix} The numerator of x (in lowest terms)
|
|
53
|
+
*/
|
|
54
|
+
return typed(name, {
|
|
55
|
+
Fraction: x => x.s * x.n,
|
|
56
|
+
BigNumber: x => {
|
|
57
|
+
const f = fraction(x);
|
|
58
|
+
return f.s * f.n;
|
|
59
|
+
},
|
|
60
|
+
'Array | Matrix': typed.referToSelf(self => x => (0, _collection.deepMap)(x, self))
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -48,6 +48,12 @@ const createMap = exports.createMap = /* #__PURE__ */(0, _factory.factory)(name,
|
|
|
48
48
|
* // It can also be called with 2N + 1 arguments: for N arrays
|
|
49
49
|
* // callback(value1, value2, index, BroadcastedArray1, BroadcastedArray2)
|
|
50
50
|
*
|
|
51
|
+
* History:
|
|
52
|
+
*
|
|
53
|
+
* v0.13 Created
|
|
54
|
+
* v1.1 Clone the indices on each callback in case callback mutates
|
|
55
|
+
* v13.1 Support multiple inputs to the callback
|
|
56
|
+
*
|
|
51
57
|
* See also:
|
|
52
58
|
*
|
|
53
59
|
* filter, forEach, sort
|
|
@@ -77,6 +77,12 @@ const createCompare = exports.createCompare = /* #__PURE__ */(0, _factory.factor
|
|
|
77
77
|
*
|
|
78
78
|
* equal, unequal, smaller, smallerEq, larger, largerEq, compareNatural, compareText
|
|
79
79
|
*
|
|
80
|
+
* History:
|
|
81
|
+
*
|
|
82
|
+
* v0.19 Created
|
|
83
|
+
* v4 Changed to compare strings by numerical value
|
|
84
|
+
* v13 Change to use separate relative and absolute tolerances
|
|
85
|
+
*
|
|
80
86
|
* @param {number | BigNumber | bigint | Fraction | Unit | string | Array | Matrix} x First value to compare
|
|
81
87
|
* @param {number | BigNumber | bigint | Fraction | Unit | string | Array | Matrix} y Second value to compare
|
|
82
88
|
* @return {number | BigNumber | bigint | Fraction | Array | Matrix} Returns the result of the comparison:
|
|
@@ -59,7 +59,7 @@ const createCompareNatural = exports.createCompareNatural = /* #__PURE__ */(0, _
|
|
|
59
59
|
* math.compareNatural('Answer: 10', 'Answer: 2') // returns 1
|
|
60
60
|
* math.compareText('Answer: 10', 'Answer: 2') // returns -1
|
|
61
61
|
* math.compare('Answer: 10', 'Answer: 2')
|
|
62
|
-
*
|
|
62
|
+
* // Error: Cannot convert "Answer: 10" to a number
|
|
63
63
|
*
|
|
64
64
|
* const a = math.unit('5 cm')
|
|
65
65
|
* const b = math.unit('40 mm')
|
|
@@ -80,6 +80,12 @@ const createCompareNatural = exports.createCompareNatural = /* #__PURE__ */(0, _
|
|
|
80
80
|
*
|
|
81
81
|
* compare, compareText
|
|
82
82
|
*
|
|
83
|
+
* History:
|
|
84
|
+
*
|
|
85
|
+
* v15.2 Handle bigints
|
|
86
|
+
* v3.14 Created
|
|
87
|
+
*
|
|
88
|
+
*
|
|
83
89
|
* @param {*} x First value to compare
|
|
84
90
|
* @param {*} y Second value to compare
|
|
85
91
|
* @return {number} Returns the result of the comparison:
|
|
@@ -95,7 +101,7 @@ const createCompareNatural = exports.createCompareNatural = /* #__PURE__ */(0, _
|
|
|
95
101
|
let c;
|
|
96
102
|
|
|
97
103
|
// numeric types
|
|
98
|
-
if ((typeX === 'number' || typeX === 'BigNumber' || typeX === 'Fraction') && (typeY === 'number' || typeY === 'BigNumber' || typeY === 'Fraction')) {
|
|
104
|
+
if ((typeX === 'number' || typeX === 'BigNumber' || typeX === 'Fraction' || typeX === 'bigint') && (typeY === 'number' || typeY === 'BigNumber' || typeY === 'Fraction' || typeY === 'bigint')) {
|
|
99
105
|
c = compare(x, y);
|
|
100
106
|
if (c.toString() !== '0') {
|
|
101
107
|
// c can be number, BigNumber, or Fraction
|
|
@@ -26,16 +26,21 @@ const createDeepEqual = exports.createDeepEqual = /* #__PURE__ */(0, _factory.fa
|
|
|
26
26
|
*
|
|
27
27
|
* math.deepEqual(2, 4) // returns false
|
|
28
28
|
*
|
|
29
|
-
* a = [2, 5, 1]
|
|
30
|
-
* b = [2, 7, 1]
|
|
29
|
+
* const a = [2, 5, 1]
|
|
30
|
+
* const b = [2, 7, 1]
|
|
31
31
|
*
|
|
32
|
-
* math.deepEqual(a, b) // returns false
|
|
32
|
+
* math.deepEqual(a, b) // returns false...
|
|
33
33
|
* math.equal(a, b) // returns [true, false, true]
|
|
34
34
|
*
|
|
35
35
|
* See also:
|
|
36
36
|
*
|
|
37
37
|
* equal, unequal
|
|
38
38
|
*
|
|
39
|
+
* History:
|
|
40
|
+
*
|
|
41
|
+
* v2 Handle Fractions
|
|
42
|
+
* v0.2 Created
|
|
43
|
+
*
|
|
39
44
|
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x First matrix to compare
|
|
40
45
|
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Second matrix to compare
|
|
41
46
|
* @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix}
|