mathjs 7.3.0 → 7.6.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 +29 -0
- package/dist/math.js +2716 -2222
- package/dist/math.min.js +5 -5
- package/dist/math.min.map +1 -1
- package/docs/datatypes/units.md +21 -0
- package/docs/reference/functions/ceil.md +10 -1
- package/docs/reference/functions/fix.md +10 -2
- package/docs/reference/functions/floor.md +12 -3
- package/docs/reference/functions/rotate.md +47 -0
- package/docs/reference/functions/rotationMatrix.md +51 -0
- package/docs/reference/functions/round.md +6 -2
- package/docs/reference/functions.md +2 -0
- package/es/entry/dependenciesAny/dependenciesCeil.generated.js +4 -0
- package/es/entry/dependenciesAny/dependenciesFix.generated.js +2 -0
- package/es/entry/dependenciesAny/dependenciesFloor.generated.js +4 -0
- package/es/entry/dependenciesAny/dependenciesRotate.generated.js +14 -0
- package/es/entry/dependenciesAny/dependenciesRotationMatrix.generated.js +30 -0
- package/es/entry/dependenciesAny.generated.js +2 -0
- package/es/entry/impureFunctionsAny.generated.js +55 -53
- package/es/entry/pureFunctionsAny.generated.js +230 -206
- package/es/expression/embeddedDocs/embeddedDocs.js +4 -0
- package/es/expression/embeddedDocs/function/matrix/rotate.js +8 -0
- package/es/expression/embeddedDocs/function/matrix/rotationMatrix.js +8 -0
- package/es/expression/node/FunctionNode.js +1 -1
- package/es/expression/node/Node.js +2 -2
- package/es/factoriesAny.js +2 -0
- package/es/function/arithmetic/ceil.js +88 -4
- package/es/function/arithmetic/fix.js +43 -6
- package/es/function/arithmetic/floor.js +90 -6
- package/es/function/arithmetic/round.js +6 -2
- package/es/function/matrix/rotate.js +78 -0
- package/es/function/matrix/rotationMatrix.js +176 -0
- package/es/function/matrix/sqrtm.js +4 -0
- package/es/function/probability/pickRandom.js +2 -6
- package/es/function/special/erf.js +1 -0
- package/es/plain/number/constants.js +1 -1
- package/es/plain/number/probability.js +1 -0
- package/es/type/unit/Unit.js +17 -18
- package/es/utils/object.js +3 -1
- package/es/version.js +1 -1
- package/examples/bignumbers.js +2 -0
- package/lib/entry/dependenciesAny/dependenciesCeil.generated.js +6 -0
- package/lib/entry/dependenciesAny/dependenciesFix.generated.js +3 -0
- package/lib/entry/dependenciesAny/dependenciesFloor.generated.js +6 -0
- package/lib/entry/dependenciesAny/dependenciesRotate.generated.js +26 -0
- package/lib/entry/dependenciesAny/dependenciesRotationMatrix.generated.js +50 -0
- package/lib/entry/dependenciesAny.generated.js +16 -0
- package/lib/entry/impureFunctionsAny.generated.js +58 -56
- package/lib/entry/mainAny.js +5 -0
- package/lib/entry/mainNumber.js +5 -0
- package/lib/entry/pureFunctionsAny.generated.js +270 -244
- package/lib/expression/embeddedDocs/embeddedDocs.js +6 -0
- package/lib/expression/embeddedDocs/function/matrix/rotate.js +15 -0
- package/lib/expression/embeddedDocs/function/matrix/rotationMatrix.js +15 -0
- package/lib/expression/node/FunctionNode.js +1 -1
- package/lib/expression/node/Node.js +2 -2
- package/lib/factoriesAny.js +16 -0
- package/lib/function/arithmetic/ceil.js +91 -4
- package/lib/function/arithmetic/fix.js +44 -6
- package/lib/function/arithmetic/floor.js +93 -6
- package/lib/function/arithmetic/round.js +6 -2
- package/lib/function/matrix/rotate.js +88 -0
- package/lib/function/matrix/rotationMatrix.js +186 -0
- package/lib/function/matrix/sqrtm.js +4 -0
- package/lib/function/probability/pickRandom.js +3 -7
- package/lib/function/special/erf.js +1 -0
- package/lib/header.js +2 -2
- package/lib/plain/bignumber/index.js +1 -0
- package/lib/plain/number/constants.js +2 -1
- package/lib/plain/number/index.js +9 -0
- package/lib/plain/number/probability.js +1 -0
- package/lib/type/unit/Unit.js +17 -18
- package/lib/utils/object.js +3 -1
- package/lib/version.js +1 -1
- package/package.json +11 -11
- package/src/core/function/import.js +2 -2
- package/src/entry/dependenciesAny/dependenciesCeil.generated.js +4 -0
- package/src/entry/dependenciesAny/dependenciesFix.generated.js +2 -0
- package/src/entry/dependenciesAny/dependenciesFloor.generated.js +4 -0
- package/src/entry/dependenciesAny/dependenciesRotate.generated.js +15 -0
- package/src/entry/dependenciesAny/dependenciesRotationMatrix.generated.js +31 -0
- package/src/entry/dependenciesAny.generated.js +2 -0
- package/src/entry/impureFunctionsAny.generated.js +84 -80
- package/src/entry/pureFunctionsAny.generated.js +75 -71
- package/src/expression/embeddedDocs/embeddedDocs.js +4 -0
- package/src/expression/embeddedDocs/function/matrix/rotate.js +19 -0
- package/src/expression/embeddedDocs/function/matrix/rotationMatrix.js +19 -0
- package/src/expression/node/FunctionNode.js +1 -1
- package/src/expression/node/Node.js +2 -1
- package/src/factoriesAny.js +2 -0
- package/src/function/arithmetic/ceil.js +63 -3
- package/src/function/arithmetic/fix.js +45 -6
- package/src/function/arithmetic/floor.js +65 -5
- package/src/function/arithmetic/round.js +6 -2
- package/src/function/matrix/rotate.js +79 -0
- package/src/function/matrix/rotationMatrix.js +186 -0
- package/src/function/matrix/sqrtm.js +4 -0
- package/src/function/probability/pickRandom.js +2 -6
- package/src/function/special/erf.js +2 -0
- package/src/plain/number/constants.js +1 -1
- package/src/plain/number/probability.js +2 -0
- package/src/type/unit/Unit.js +18 -21
- package/src/utils/object.js +3 -1
- package/src/version.js +1 -1
|
@@ -437,6 +437,10 @@ var _column = require("./function/matrix/column");
|
|
|
437
437
|
|
|
438
438
|
var _row = require("./function/matrix/row");
|
|
439
439
|
|
|
440
|
+
var _rotationMatrix = require("./function/matrix/rotationMatrix");
|
|
441
|
+
|
|
442
|
+
var _rotate = require("./function/matrix/rotate");
|
|
443
|
+
|
|
440
444
|
var embeddedDocs = {
|
|
441
445
|
// construction functions
|
|
442
446
|
bignumber: _bignumber.bignumberDocs,
|
|
@@ -780,6 +784,8 @@ var embeddedDocs = {
|
|
|
780
784
|
range: _range.rangeDocs,
|
|
781
785
|
resize: _resize.resizeDocs,
|
|
782
786
|
reshape: _reshape.reshapeDocs,
|
|
787
|
+
rotate: _rotate.rotateDocs,
|
|
788
|
+
rotationMatrix: _rotationMatrix.rotationMatrixDocs,
|
|
783
789
|
row: _row.rowDocs,
|
|
784
790
|
size: _size.sizeDocs,
|
|
785
791
|
sort: _sort.sortDocs,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rotateDocs = void 0;
|
|
7
|
+
var rotateDocs = {
|
|
8
|
+
name: 'rotate',
|
|
9
|
+
category: 'Matrix',
|
|
10
|
+
syntax: ['rotate(w, theta)', 'rotate(w, theta, v)'],
|
|
11
|
+
description: 'Returns a 2-D rotation matrix (2x2) for a given angle (in radians). ' + 'Returns a 2-D rotation matrix (3x3) of a given angle (in radians) around given axis.',
|
|
12
|
+
examples: ['rotate([1, 0], math.pi / 2)', 'rotate(matrix([1, 0]), unit("35deg"))', 'rotate([1, 0, 0], unit("90deg"), [0, 0, 1])', 'rotate(matrix([1, 0, 0]), unit("90deg"), matrix([0, 0, 1]))'],
|
|
13
|
+
seealso: ['matrix', 'rotationMatrix']
|
|
14
|
+
};
|
|
15
|
+
exports.rotateDocs = rotateDocs;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rotationMatrixDocs = void 0;
|
|
7
|
+
var rotationMatrixDocs = {
|
|
8
|
+
name: 'rotationMatrix',
|
|
9
|
+
category: 'Matrix',
|
|
10
|
+
syntax: ['rotationMatrix(theta)', 'rotationMatrix(theta, v)', 'rotationMatrix(theta, v, format)'],
|
|
11
|
+
description: 'Returns a 2-D rotation matrix (2x2) for a given angle (in radians). ' + 'Returns a 2-D rotation matrix (3x3) of a given angle (in radians) around given axis.',
|
|
12
|
+
examples: ['rotationMatrix(pi / 2)', 'rotationMatrix(unit("45deg"), [0, 0, 1])', 'rotationMatrix(1, matrix([0, 0, 1]), "sparse")'],
|
|
13
|
+
seealso: ['cos', 'sin']
|
|
14
|
+
};
|
|
15
|
+
exports.rotationMatrixDocs = rotationMatrixDocs;
|
|
@@ -303,7 +303,7 @@ var createFunctionNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
|
303
303
|
var latex = ''; // Match everything of the form ${identifier} or ${identifier[2]} or $$
|
|
304
304
|
// while submatching identifier and 2 (in the second case)
|
|
305
305
|
|
|
306
|
-
var regex =
|
|
306
|
+
var regex = /\$(?:\{([a-z_][a-z_0-9]*)(?:\[([0-9]+)\])?\}|\$)/gi;
|
|
307
307
|
var inputPos = 0; // position in the input string
|
|
308
308
|
|
|
309
309
|
var match;
|
|
@@ -134,8 +134,8 @@ var createNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
|
134
134
|
|
|
135
135
|
Node.prototype.traverse = function (callback) {
|
|
136
136
|
// execute callback for itself
|
|
137
|
-
|
|
138
|
-
// recursively traverse over all childs of a node
|
|
137
|
+
// eslint-disable-next-line
|
|
138
|
+
callback(this, null, null); // recursively traverse over all childs of a node
|
|
139
139
|
|
|
140
140
|
function _traverse(node, callback) {
|
|
141
141
|
node.forEach(function (child, path, parent) {
|
package/lib/factoriesAny.js
CHANGED
|
@@ -483,6 +483,18 @@ Object.defineProperty(exports, "createResize", {
|
|
|
483
483
|
return _resize.createResize;
|
|
484
484
|
}
|
|
485
485
|
});
|
|
486
|
+
Object.defineProperty(exports, "createRotate", {
|
|
487
|
+
enumerable: true,
|
|
488
|
+
get: function get() {
|
|
489
|
+
return _rotate.createRotate;
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
Object.defineProperty(exports, "createRotationMatrix", {
|
|
493
|
+
enumerable: true,
|
|
494
|
+
get: function get() {
|
|
495
|
+
return _rotationMatrix.createRotationMatrix;
|
|
496
|
+
}
|
|
497
|
+
});
|
|
486
498
|
Object.defineProperty(exports, "createRow", {
|
|
487
499
|
enumerable: true,
|
|
488
500
|
get: function get() {
|
|
@@ -2126,6 +2138,10 @@ var _reshape = require("./function/matrix/reshape");
|
|
|
2126
2138
|
|
|
2127
2139
|
var _resize = require("./function/matrix/resize");
|
|
2128
2140
|
|
|
2141
|
+
var _rotate = require("./function/matrix/rotate");
|
|
2142
|
+
|
|
2143
|
+
var _rotationMatrix = require("./function/matrix/rotationMatrix");
|
|
2144
|
+
|
|
2129
2145
|
var _row = require("./function/matrix/row");
|
|
2130
2146
|
|
|
2131
2147
|
var _size = require("./function/matrix/size");
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createCeil = void 0;
|
|
7
7
|
|
|
8
|
+
var _decimal = require("decimal.js");
|
|
9
|
+
|
|
8
10
|
var _factory = require("../../utils/factory");
|
|
9
11
|
|
|
10
12
|
var _collection = require("../../utils/collection");
|
|
@@ -15,13 +17,37 @@ var _nearlyEqual = require("../../utils/bignumber/nearlyEqual");
|
|
|
15
17
|
|
|
16
18
|
var _number2 = require("../../plain/number");
|
|
17
19
|
|
|
20
|
+
var _algorithm = require("../../type/matrix/utils/algorithm11");
|
|
21
|
+
|
|
22
|
+
var _algorithm2 = require("../../type/matrix/utils/algorithm14");
|
|
23
|
+
|
|
24
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
25
|
+
|
|
26
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
27
|
+
|
|
28
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
29
|
+
|
|
30
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
31
|
+
|
|
32
|
+
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
33
|
+
|
|
34
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
35
|
+
|
|
18
36
|
var name = 'ceil';
|
|
19
|
-
var dependencies = ['typed', 'config', 'round'];
|
|
37
|
+
var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar'];
|
|
20
38
|
var createCeil = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
|
21
39
|
var typed = _ref.typed,
|
|
22
40
|
config = _ref.config,
|
|
23
|
-
round = _ref.round
|
|
24
|
-
|
|
41
|
+
round = _ref.round,
|
|
42
|
+
matrix = _ref.matrix,
|
|
43
|
+
equalScalar = _ref.equalScalar;
|
|
44
|
+
var algorithm11 = (0, _algorithm.createAlgorithm11)({
|
|
45
|
+
typed: typed,
|
|
46
|
+
equalScalar: equalScalar
|
|
47
|
+
});
|
|
48
|
+
var algorithm14 = (0, _algorithm2.createAlgorithm14)({
|
|
49
|
+
typed: typed
|
|
50
|
+
});
|
|
25
51
|
/**
|
|
26
52
|
* Round a value towards plus infinity
|
|
27
53
|
* If `x` is complex, both real and imaginary part are rounded towards plus infinity.
|
|
@@ -30,6 +56,7 @@ var createCeil = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
|
30
56
|
* Syntax:
|
|
31
57
|
*
|
|
32
58
|
* math.ceil(x)
|
|
59
|
+
* math.ceil(x, n)
|
|
33
60
|
*
|
|
34
61
|
* Examples:
|
|
35
62
|
*
|
|
@@ -38,18 +65,27 @@ var createCeil = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
|
38
65
|
* math.ceil(-4.2) // returns number -4
|
|
39
66
|
* math.ceil(-4.7) // returns number -4
|
|
40
67
|
*
|
|
41
|
-
*
|
|
68
|
+
* math.ceil(3.212, 2) // returns number 3.22
|
|
69
|
+
* math.ceil(3.288, 2) // returns number 3.29
|
|
70
|
+
* math.ceil(-4.212, 2) // returns number -4.21
|
|
71
|
+
* math.ceil(-4.782, 2) // returns number -4.78
|
|
72
|
+
*
|
|
73
|
+
* const c = math.complex(3.24, -2.71)
|
|
42
74
|
* math.ceil(c) // returns Complex 4 - 2i
|
|
75
|
+
* math.ceil(c, 1) // returns Complex 3.3 - 2.7i
|
|
43
76
|
*
|
|
44
77
|
* math.ceil([3.2, 3.8, -4.7]) // returns Array [4, 4, -4]
|
|
78
|
+
* math.ceil([3.21, 3.82, -4.71], 1) // returns Array [3.3, 3.9, -4.7]
|
|
45
79
|
*
|
|
46
80
|
* See also:
|
|
47
81
|
*
|
|
48
82
|
* floor, fix, round
|
|
49
83
|
*
|
|
50
84
|
* @param {number | BigNumber | Fraction | Complex | Array | Matrix} x Number to be rounded
|
|
85
|
+
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
|
51
86
|
* @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
|
|
52
87
|
*/
|
|
88
|
+
|
|
53
89
|
return typed('ceil', {
|
|
54
90
|
number: function number(x) {
|
|
55
91
|
if ((0, _number.nearlyEqual)(x, round(x), config.epsilon)) {
|
|
@@ -58,9 +94,32 @@ var createCeil = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
|
58
94
|
return (0, _number2.ceilNumber)(x);
|
|
59
95
|
}
|
|
60
96
|
},
|
|
97
|
+
'number, number': function numberNumber(x, n) {
|
|
98
|
+
if ((0, _number.nearlyEqual)(x, round(x, n), config.epsilon)) {
|
|
99
|
+
return round(x, n);
|
|
100
|
+
} else {
|
|
101
|
+
var _$split = "".concat(x, "e").split('e'),
|
|
102
|
+
_$split2 = _slicedToArray(_$split, 2),
|
|
103
|
+
number = _$split2[0],
|
|
104
|
+
exponent = _$split2[1];
|
|
105
|
+
|
|
106
|
+
var result = Math.ceil(Number("".concat(number, "e").concat(Number(exponent) + n)));
|
|
107
|
+
|
|
108
|
+
var _$split3 = "".concat(result, "e").split('e');
|
|
109
|
+
|
|
110
|
+
var _$split4 = _slicedToArray(_$split3, 2);
|
|
111
|
+
|
|
112
|
+
number = _$split4[0];
|
|
113
|
+
exponent = _$split4[1];
|
|
114
|
+
return Number("".concat(number, "e").concat(Number(exponent) - n));
|
|
115
|
+
}
|
|
116
|
+
},
|
|
61
117
|
Complex: function Complex(x) {
|
|
62
118
|
return x.ceil();
|
|
63
119
|
},
|
|
120
|
+
'Complex, number': function ComplexNumber(x, n) {
|
|
121
|
+
return x.ceil(n);
|
|
122
|
+
},
|
|
64
123
|
BigNumber: function BigNumber(x) {
|
|
65
124
|
if ((0, _nearlyEqual.nearlyEqual)(x, round(x), config.epsilon)) {
|
|
66
125
|
return round(x);
|
|
@@ -68,12 +127,40 @@ var createCeil = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
|
68
127
|
return x.ceil();
|
|
69
128
|
}
|
|
70
129
|
},
|
|
130
|
+
'BigNumber, BigNumber': function BigNumberBigNumber(x, n) {
|
|
131
|
+
if ((0, _nearlyEqual.nearlyEqual)(x, round(x, n), config.epsilon)) {
|
|
132
|
+
return round(x, n);
|
|
133
|
+
} else {
|
|
134
|
+
return x.toDecimalPlaces(n.toNumber(), _decimal.Decimal.ROUND_CEIL);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
71
137
|
Fraction: function Fraction(x) {
|
|
72
138
|
return x.ceil();
|
|
73
139
|
},
|
|
140
|
+
'Fraction, number': function FractionNumber(x, n) {
|
|
141
|
+
return x.ceil(n);
|
|
142
|
+
},
|
|
74
143
|
'Array | Matrix': function ArrayMatrix(x) {
|
|
75
144
|
// deep map collection, skip zeros since ceil(0) = 0
|
|
76
145
|
return (0, _collection.deepMap)(x, this, true);
|
|
146
|
+
},
|
|
147
|
+
'Array | Matrix, number': function ArrayMatrixNumber(x, n) {
|
|
148
|
+
var _this = this;
|
|
149
|
+
|
|
150
|
+
// deep map collection, skip zeros since ceil(0) = 0
|
|
151
|
+
return (0, _collection.deepMap)(x, function (i) {
|
|
152
|
+
return _this(i, n);
|
|
153
|
+
}, true);
|
|
154
|
+
},
|
|
155
|
+
'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
|
156
|
+
return algorithm11(x, y, this, false);
|
|
157
|
+
},
|
|
158
|
+
'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
|
159
|
+
return algorithm14(x, y, this, false);
|
|
160
|
+
},
|
|
161
|
+
'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
|
|
162
|
+
// use matrix implementation
|
|
163
|
+
return algorithm14(matrix(y), x, this, true).valueOf();
|
|
77
164
|
}
|
|
78
165
|
});
|
|
79
166
|
});
|
|
@@ -9,14 +9,19 @@ var _factory = require("../../utils/factory");
|
|
|
9
9
|
|
|
10
10
|
var _collection = require("../../utils/collection");
|
|
11
11
|
|
|
12
|
+
var _algorithm = require("../../type/matrix/utils/algorithm14");
|
|
13
|
+
|
|
12
14
|
var name = 'fix';
|
|
13
|
-
var dependencies = ['typed', 'Complex', 'ceil', 'floor'];
|
|
15
|
+
var dependencies = ['typed', 'Complex', 'matrix', 'ceil', 'floor'];
|
|
14
16
|
var createFix = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
|
15
17
|
var typed = _ref.typed,
|
|
16
18
|
_Complex = _ref.Complex,
|
|
19
|
+
matrix = _ref.matrix,
|
|
17
20
|
ceil = _ref.ceil,
|
|
18
21
|
floor = _ref.floor;
|
|
19
|
-
|
|
22
|
+
var algorithm14 = (0, _algorithm.createAlgorithm14)({
|
|
23
|
+
typed: typed
|
|
24
|
+
});
|
|
20
25
|
/**
|
|
21
26
|
* Round a value towards zero.
|
|
22
27
|
* For matrices, the function is evaluated element wise.
|
|
@@ -32,34 +37,67 @@ var createFix = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
|
|
|
32
37
|
* math.fix(-4.2) // returns number -4
|
|
33
38
|
* math.fix(-4.7) // returns number -4
|
|
34
39
|
*
|
|
35
|
-
*
|
|
40
|
+
* math.fix(3.12, 1) // returns number 3.1
|
|
41
|
+
* math.fix(3.18, 1) // returns number 3.1
|
|
42
|
+
* math.fix(-4.12, 1) // returns number -4.1
|
|
43
|
+
* math.fix(-4.17, 1) // returns number -4.1
|
|
44
|
+
*
|
|
45
|
+
* const c = math.complex(3.22, -2.78)
|
|
36
46
|
* math.fix(c) // returns Complex 3 - 2i
|
|
47
|
+
* math.fix(c, 1) // returns Complex 3.2 - 2.7i
|
|
37
48
|
*
|
|
38
|
-
* math.fix([3.2, 3.8, -4.7])
|
|
49
|
+
* math.fix([3.2, 3.8, -4.7]) // returns Array [3, 3, -4]
|
|
50
|
+
* math.fix([3.2, 3.8, -4.7], 1) // returns Array [3.2, 3.8, -4.7]
|
|
39
51
|
*
|
|
40
52
|
* See also:
|
|
41
53
|
*
|
|
42
54
|
* ceil, floor, round
|
|
43
55
|
*
|
|
44
|
-
* @param
|
|
45
|
-
* @
|
|
56
|
+
* @param {number | BigNumber | Fraction | Complex | Array | Matrix} x Number to be rounded
|
|
57
|
+
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
|
58
|
+
* @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
|
|
46
59
|
*/
|
|
60
|
+
|
|
47
61
|
return typed('fix', {
|
|
48
62
|
number: function number(x) {
|
|
49
63
|
return x > 0 ? floor(x) : ceil(x);
|
|
50
64
|
},
|
|
65
|
+
'number, number | BigNumber': function numberNumberBigNumber(x, n) {
|
|
66
|
+
return x > 0 ? floor(x, n) : ceil(x, n);
|
|
67
|
+
},
|
|
51
68
|
Complex: function Complex(x) {
|
|
52
69
|
return new _Complex(x.re > 0 ? Math.floor(x.re) : Math.ceil(x.re), x.im > 0 ? Math.floor(x.im) : Math.ceil(x.im));
|
|
53
70
|
},
|
|
71
|
+
'Complex, number | BigNumber': function ComplexNumberBigNumber(x, n) {
|
|
72
|
+
return new _Complex(x.re > 0 ? floor(x.re, n) : ceil(x.re, n), x.im > 0 ? floor(x.im, n) : ceil(x.im, n));
|
|
73
|
+
},
|
|
54
74
|
BigNumber: function BigNumber(x) {
|
|
55
75
|
return x.isNegative() ? ceil(x) : floor(x);
|
|
56
76
|
},
|
|
77
|
+
'BigNumber, number | BigNumber': function BigNumberNumberBigNumber(x, n) {
|
|
78
|
+
return x.isNegative() ? ceil(x, n) : floor(x, n);
|
|
79
|
+
},
|
|
57
80
|
Fraction: function Fraction(x) {
|
|
58
81
|
return x.s < 0 ? x.ceil() : x.floor();
|
|
59
82
|
},
|
|
83
|
+
'Fraction, number | BigNumber': function FractionNumberBigNumber(x, n) {
|
|
84
|
+
return x.s < 0 ? x.ceil(n) : x.floor(n);
|
|
85
|
+
},
|
|
60
86
|
'Array | Matrix': function ArrayMatrix(x) {
|
|
61
87
|
// deep map collection, skip zeros since fix(0) = 0
|
|
62
88
|
return (0, _collection.deepMap)(x, this, true);
|
|
89
|
+
},
|
|
90
|
+
'Array | Matrix, number | BigNumber': function ArrayMatrixNumberBigNumber(x, n) {
|
|
91
|
+
var _this = this;
|
|
92
|
+
|
|
93
|
+
// deep map collection, skip zeros since fix(0) = 0
|
|
94
|
+
return (0, _collection.deepMap)(x, function (i) {
|
|
95
|
+
return _this(i, n);
|
|
96
|
+
}, true);
|
|
97
|
+
},
|
|
98
|
+
'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
|
|
99
|
+
// use matrix implementation
|
|
100
|
+
return algorithm14(matrix(y), x, this, true).valueOf();
|
|
63
101
|
}
|
|
64
102
|
});
|
|
65
103
|
});
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createFloor = void 0;
|
|
7
7
|
|
|
8
|
+
var _decimal = require("decimal.js");
|
|
9
|
+
|
|
8
10
|
var _factory = require("../../utils/factory");
|
|
9
11
|
|
|
10
12
|
var _collection = require("../../utils/collection");
|
|
@@ -13,13 +15,37 @@ var _number = require("../../utils/number");
|
|
|
13
15
|
|
|
14
16
|
var _nearlyEqual = require("../../utils/bignumber/nearlyEqual");
|
|
15
17
|
|
|
18
|
+
var _algorithm = require("../../type/matrix/utils/algorithm11");
|
|
19
|
+
|
|
20
|
+
var _algorithm2 = require("../../type/matrix/utils/algorithm14");
|
|
21
|
+
|
|
22
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
23
|
+
|
|
24
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
25
|
+
|
|
26
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
|
+
|
|
28
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
29
|
+
|
|
30
|
+
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
31
|
+
|
|
32
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
33
|
+
|
|
16
34
|
var name = 'floor';
|
|
17
|
-
var dependencies = ['typed', 'config', 'round'];
|
|
35
|
+
var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar'];
|
|
18
36
|
var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
|
19
37
|
var typed = _ref.typed,
|
|
20
38
|
config = _ref.config,
|
|
21
|
-
round = _ref.round
|
|
22
|
-
|
|
39
|
+
round = _ref.round,
|
|
40
|
+
matrix = _ref.matrix,
|
|
41
|
+
equalScalar = _ref.equalScalar;
|
|
42
|
+
var algorithm11 = (0, _algorithm.createAlgorithm11)({
|
|
43
|
+
typed: typed,
|
|
44
|
+
equalScalar: equalScalar
|
|
45
|
+
});
|
|
46
|
+
var algorithm14 = (0, _algorithm2.createAlgorithm14)({
|
|
47
|
+
typed: typed
|
|
48
|
+
});
|
|
23
49
|
/**
|
|
24
50
|
* Round a value towards minus infinity.
|
|
25
51
|
* For matrices, the function is evaluated element wise.
|
|
@@ -27,6 +53,7 @@ var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
|
27
53
|
* Syntax:
|
|
28
54
|
*
|
|
29
55
|
* math.floor(x)
|
|
56
|
+
* math.floor(x, n)
|
|
30
57
|
*
|
|
31
58
|
* Examples:
|
|
32
59
|
*
|
|
@@ -35,18 +62,27 @@ var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
|
35
62
|
* math.floor(-4.2) // returns number -5
|
|
36
63
|
* math.floor(-4.7) // returns number -5
|
|
37
64
|
*
|
|
38
|
-
*
|
|
39
|
-
* math.floor(
|
|
65
|
+
* math.floor(3.212, 2) // returns number 3.21
|
|
66
|
+
* math.floor(3.288, 2) // returns number 3.28
|
|
67
|
+
* math.floor(-4.212, 2) // returns number -4.22
|
|
68
|
+
* math.floor(-4.782, 2) // returns number -4.79
|
|
40
69
|
*
|
|
41
|
-
* math.
|
|
70
|
+
* const c = math.complex(3.24, -2.71)
|
|
71
|
+
* math.floor(c) // returns Complex 3 - 3i
|
|
72
|
+
* math.floor(c, 1) // returns Complex 3.2 - 2.8i
|
|
73
|
+
*
|
|
74
|
+
* math.floor([3.2, 3.8, -4.7]) // returns Array [3, 3, -5]
|
|
75
|
+
* math.floor([3.21, 3.82, -4.71], 1) // returns Array [3.2, 3.8, -4.8]
|
|
42
76
|
*
|
|
43
77
|
* See also:
|
|
44
78
|
*
|
|
45
79
|
* ceil, fix, round
|
|
46
80
|
*
|
|
47
81
|
* @param {number | BigNumber | Fraction | Complex | Array | Matrix} x Number to be rounded
|
|
82
|
+
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
|
48
83
|
* @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
|
|
49
84
|
*/
|
|
85
|
+
|
|
50
86
|
return typed('floor', {
|
|
51
87
|
number: function number(x) {
|
|
52
88
|
if ((0, _number.nearlyEqual)(x, round(x), config.epsilon)) {
|
|
@@ -55,9 +91,32 @@ var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
|
55
91
|
return Math.floor(x);
|
|
56
92
|
}
|
|
57
93
|
},
|
|
94
|
+
'number, number': function numberNumber(x, n) {
|
|
95
|
+
if ((0, _number.nearlyEqual)(x, round(x, n), config.epsilon)) {
|
|
96
|
+
return round(x, n);
|
|
97
|
+
} else {
|
|
98
|
+
var _$split = "".concat(x, "e").split('e'),
|
|
99
|
+
_$split2 = _slicedToArray(_$split, 2),
|
|
100
|
+
number = _$split2[0],
|
|
101
|
+
exponent = _$split2[1];
|
|
102
|
+
|
|
103
|
+
var result = Math.floor(Number("".concat(number, "e").concat(Number(exponent) + n)));
|
|
104
|
+
|
|
105
|
+
var _$split3 = "".concat(result, "e").split('e');
|
|
106
|
+
|
|
107
|
+
var _$split4 = _slicedToArray(_$split3, 2);
|
|
108
|
+
|
|
109
|
+
number = _$split4[0];
|
|
110
|
+
exponent = _$split4[1];
|
|
111
|
+
return Number("".concat(number, "e").concat(Number(exponent) - n));
|
|
112
|
+
}
|
|
113
|
+
},
|
|
58
114
|
Complex: function Complex(x) {
|
|
59
115
|
return x.floor();
|
|
60
116
|
},
|
|
117
|
+
'Complex, number': function ComplexNumber(x, n) {
|
|
118
|
+
return x.floor(n);
|
|
119
|
+
},
|
|
61
120
|
BigNumber: function BigNumber(x) {
|
|
62
121
|
if ((0, _nearlyEqual.nearlyEqual)(x, round(x), config.epsilon)) {
|
|
63
122
|
return round(x);
|
|
@@ -65,12 +124,40 @@ var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
|
65
124
|
return x.floor();
|
|
66
125
|
}
|
|
67
126
|
},
|
|
127
|
+
'BigNumber, BigNumber': function BigNumberBigNumber(x, n) {
|
|
128
|
+
if ((0, _nearlyEqual.nearlyEqual)(x, round(x, n), config.epsilon)) {
|
|
129
|
+
return round(x, n);
|
|
130
|
+
} else {
|
|
131
|
+
return x.toDecimalPlaces(n.toNumber(), _decimal.Decimal.ROUND_FLOOR);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
68
134
|
Fraction: function Fraction(x) {
|
|
69
135
|
return x.floor();
|
|
70
136
|
},
|
|
137
|
+
'Fraction, number': function FractionNumber(x, n) {
|
|
138
|
+
return x.floor(n);
|
|
139
|
+
},
|
|
71
140
|
'Array | Matrix': function ArrayMatrix(x) {
|
|
72
141
|
// deep map collection, skip zeros since floor(0) = 0
|
|
73
142
|
return (0, _collection.deepMap)(x, this, true);
|
|
143
|
+
},
|
|
144
|
+
'Array | Matrix, number': function ArrayMatrixNumber(x, n) {
|
|
145
|
+
var _this = this;
|
|
146
|
+
|
|
147
|
+
// deep map collection, skip zeros since ceil(0) = 0
|
|
148
|
+
return (0, _collection.deepMap)(x, function (i) {
|
|
149
|
+
return _this(i, n);
|
|
150
|
+
}, true);
|
|
151
|
+
},
|
|
152
|
+
'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
|
153
|
+
return algorithm11(x, y, this, false);
|
|
154
|
+
},
|
|
155
|
+
'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
|
156
|
+
return algorithm14(x, y, this, false);
|
|
157
|
+
},
|
|
158
|
+
'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
|
|
159
|
+
// use matrix implementation
|
|
160
|
+
return algorithm14(matrix(y), x, this, true).valueOf();
|
|
74
161
|
}
|
|
75
162
|
});
|
|
76
163
|
});
|
|
@@ -57,10 +57,14 @@ var createRound = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
|
57
57
|
*
|
|
58
58
|
* Examples:
|
|
59
59
|
*
|
|
60
|
-
* math.round(3.
|
|
61
|
-
* math.round(3.
|
|
60
|
+
* math.round(3.22) // returns number 3
|
|
61
|
+
* math.round(3.82) // returns number 4
|
|
62
62
|
* math.round(-4.2) // returns number -4
|
|
63
63
|
* math.round(-4.7) // returns number -5
|
|
64
|
+
* math.round(3.22, 1) // returns number 3.2
|
|
65
|
+
* math.round(3.88, 1) // returns number 3.8
|
|
66
|
+
* math.round(-4.21, 1) // returns number -4.2
|
|
67
|
+
* math.round(-4.71, 1) // returns number -4.7
|
|
64
68
|
* math.round(math.pi, 3) // returns number 3.142
|
|
65
69
|
* math.round(123.45678, 2) // returns number 123.46
|
|
66
70
|
*
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createRotate = void 0;
|
|
7
|
+
|
|
8
|
+
var _factory = require("../../utils/factory");
|
|
9
|
+
|
|
10
|
+
var _array = require("../../utils/array");
|
|
11
|
+
|
|
12
|
+
var name = 'rotate';
|
|
13
|
+
var dependencies = ['typed', 'multiply', 'rotationMatrix'];
|
|
14
|
+
var createRotate = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
|
15
|
+
var typed = _ref.typed,
|
|
16
|
+
multiply = _ref.multiply,
|
|
17
|
+
rotationMatrix = _ref.rotationMatrix;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Rotate a vector of size 1x2 counter-clockwise by a given angle
|
|
21
|
+
* Rotate a vector of size 1x3 counter-clockwise by a given angle around the given axis
|
|
22
|
+
*
|
|
23
|
+
* Syntax:
|
|
24
|
+
*
|
|
25
|
+
* math.rotate(w, theta)
|
|
26
|
+
* math.rotate(w, theta, v)
|
|
27
|
+
*
|
|
28
|
+
* Examples:
|
|
29
|
+
*
|
|
30
|
+
* math.rotate([11, 12], math.pi / 2) // returns matrix([-12, 11])
|
|
31
|
+
* math.rotate(matrix([11, 12]), math.pi / 2) // returns matrix([-12, 11])
|
|
32
|
+
*
|
|
33
|
+
* math.rotate([1, 0, 0], unit('90deg'), [0, 0, 1]) // returns matrix([0, 1, 0])
|
|
34
|
+
* math.rotate(matrix([1, 0, 0]), unit('90deg'), [0, 0, 1]) // returns matrix([0, 1, 0])
|
|
35
|
+
*
|
|
36
|
+
* math.rotate([1, 0], math.complex(1 + i)) // returns matrix([cos(1 + i) - sin(1 + i), sin(1 + i) + cos(1 + i)])
|
|
37
|
+
*
|
|
38
|
+
* See also:
|
|
39
|
+
*
|
|
40
|
+
* matrix, rotationMatrix
|
|
41
|
+
*
|
|
42
|
+
* @param {Array | Matrix} w Vector to rotate
|
|
43
|
+
* @param {number | BigNumber | Complex | Unit} theta Rotation angle
|
|
44
|
+
* @param {Array | Matrix} [v] Rotation axis
|
|
45
|
+
* @return {Array | Matrix} Multiplication of the rotation matrix and w
|
|
46
|
+
*/
|
|
47
|
+
return typed(name, {
|
|
48
|
+
'Array , number | BigNumber | Complex | Unit': function ArrayNumberBigNumberComplexUnit(w, theta) {
|
|
49
|
+
_validateSize(w, 2);
|
|
50
|
+
|
|
51
|
+
var matrixRes = multiply(rotationMatrix(theta), w);
|
|
52
|
+
return matrixRes.toArray();
|
|
53
|
+
},
|
|
54
|
+
'Matrix , number | BigNumber | Complex | Unit': function MatrixNumberBigNumberComplexUnit(w, theta) {
|
|
55
|
+
_validateSize(w, 2);
|
|
56
|
+
|
|
57
|
+
return multiply(rotationMatrix(theta), w);
|
|
58
|
+
},
|
|
59
|
+
'Array, number | BigNumber | Complex | Unit, Array | Matrix': function ArrayNumberBigNumberComplexUnitArrayMatrix(w, theta, v) {
|
|
60
|
+
_validateSize(w, 3);
|
|
61
|
+
|
|
62
|
+
var matrixRes = multiply(rotationMatrix(theta, v), w);
|
|
63
|
+
return matrixRes;
|
|
64
|
+
},
|
|
65
|
+
'Matrix, number | BigNumber | Complex | Unit, Array | Matrix': function MatrixNumberBigNumberComplexUnitArrayMatrix(w, theta, v) {
|
|
66
|
+
_validateSize(w, 3);
|
|
67
|
+
|
|
68
|
+
return multiply(rotationMatrix(theta, v), w);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
function _validateSize(v, expectedSize) {
|
|
73
|
+
var actualSize = Array.isArray(v) ? (0, _array.arraySize)(v) : v.size();
|
|
74
|
+
|
|
75
|
+
if (actualSize.length > 2) {
|
|
76
|
+
throw new RangeError("Vector must be of dimensions 1x".concat(expectedSize));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (actualSize.length === 2 && actualSize[1] !== 1) {
|
|
80
|
+
throw new RangeError("Vector must be of dimensions 1x".concat(expectedSize));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (actualSize[0] !== expectedSize) {
|
|
84
|
+
throw new RangeError("Vector must be of dimensions 1x".concat(expectedSize));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
exports.createRotate = createRotate;
|