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
|
@@ -123,8 +123,8 @@ export var createNode = /* #__PURE__ */factory(name, dependencies, function (_re
|
|
|
123
123
|
|
|
124
124
|
Node.prototype.traverse = function (callback) {
|
|
125
125
|
// execute callback for itself
|
|
126
|
-
|
|
127
|
-
// recursively traverse over all childs of a node
|
|
126
|
+
// eslint-disable-next-line
|
|
127
|
+
callback(this, null, null); // recursively traverse over all childs of a node
|
|
128
128
|
|
|
129
129
|
function _traverse(node, callback) {
|
|
130
130
|
node.forEach(function (child, path, parent) {
|
package/es/factoriesAny.js
CHANGED
|
@@ -78,6 +78,8 @@ export { createOnes } from './function/matrix/ones';
|
|
|
78
78
|
export { createRange } from './function/matrix/range';
|
|
79
79
|
export { createReshape } from './function/matrix/reshape';
|
|
80
80
|
export { createResize } from './function/matrix/resize';
|
|
81
|
+
export { createRotate } from './function/matrix/rotate';
|
|
82
|
+
export { createRotationMatrix } from './function/matrix/rotationMatrix';
|
|
81
83
|
export { createRow } from './function/matrix/row';
|
|
82
84
|
export { createSize } from './function/matrix/size';
|
|
83
85
|
export { createSqueeze } from './function/matrix/squeeze';
|
|
@@ -1,15 +1,38 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
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."); }
|
|
4
|
+
|
|
5
|
+
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); }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import { Decimal } from 'decimal.js';
|
|
1
14
|
import { factory } from '../../utils/factory';
|
|
2
15
|
import { deepMap } from '../../utils/collection';
|
|
3
16
|
import { nearlyEqual } from '../../utils/number';
|
|
4
17
|
import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual';
|
|
5
18
|
import { ceilNumber } from '../../plain/number';
|
|
19
|
+
import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11';
|
|
20
|
+
import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14';
|
|
6
21
|
var name = 'ceil';
|
|
7
|
-
var dependencies = ['typed', 'config', 'round'];
|
|
22
|
+
var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar'];
|
|
8
23
|
export var createCeil = /* #__PURE__ */factory(name, dependencies, function (_ref) {
|
|
9
24
|
var typed = _ref.typed,
|
|
10
25
|
config = _ref.config,
|
|
11
|
-
round = _ref.round
|
|
12
|
-
|
|
26
|
+
round = _ref.round,
|
|
27
|
+
matrix = _ref.matrix,
|
|
28
|
+
equalScalar = _ref.equalScalar;
|
|
29
|
+
var algorithm11 = createAlgorithm11({
|
|
30
|
+
typed: typed,
|
|
31
|
+
equalScalar: equalScalar
|
|
32
|
+
});
|
|
33
|
+
var algorithm14 = createAlgorithm14({
|
|
34
|
+
typed: typed
|
|
35
|
+
});
|
|
13
36
|
/**
|
|
14
37
|
* Round a value towards plus infinity
|
|
15
38
|
* If `x` is complex, both real and imaginary part are rounded towards plus infinity.
|
|
@@ -18,6 +41,7 @@ export var createCeil = /* #__PURE__ */factory(name, dependencies, function (_re
|
|
|
18
41
|
* Syntax:
|
|
19
42
|
*
|
|
20
43
|
* math.ceil(x)
|
|
44
|
+
* math.ceil(x, n)
|
|
21
45
|
*
|
|
22
46
|
* Examples:
|
|
23
47
|
*
|
|
@@ -26,18 +50,27 @@ export var createCeil = /* #__PURE__ */factory(name, dependencies, function (_re
|
|
|
26
50
|
* math.ceil(-4.2) // returns number -4
|
|
27
51
|
* math.ceil(-4.7) // returns number -4
|
|
28
52
|
*
|
|
29
|
-
*
|
|
53
|
+
* math.ceil(3.212, 2) // returns number 3.22
|
|
54
|
+
* math.ceil(3.288, 2) // returns number 3.29
|
|
55
|
+
* math.ceil(-4.212, 2) // returns number -4.21
|
|
56
|
+
* math.ceil(-4.782, 2) // returns number -4.78
|
|
57
|
+
*
|
|
58
|
+
* const c = math.complex(3.24, -2.71)
|
|
30
59
|
* math.ceil(c) // returns Complex 4 - 2i
|
|
60
|
+
* math.ceil(c, 1) // returns Complex 3.3 - 2.7i
|
|
31
61
|
*
|
|
32
62
|
* math.ceil([3.2, 3.8, -4.7]) // returns Array [4, 4, -4]
|
|
63
|
+
* math.ceil([3.21, 3.82, -4.71], 1) // returns Array [3.3, 3.9, -4.7]
|
|
33
64
|
*
|
|
34
65
|
* See also:
|
|
35
66
|
*
|
|
36
67
|
* floor, fix, round
|
|
37
68
|
*
|
|
38
69
|
* @param {number | BigNumber | Fraction | Complex | Array | Matrix} x Number to be rounded
|
|
70
|
+
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
|
39
71
|
* @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
|
|
40
72
|
*/
|
|
73
|
+
|
|
41
74
|
return typed('ceil', {
|
|
42
75
|
number: function number(x) {
|
|
43
76
|
if (nearlyEqual(x, round(x), config.epsilon)) {
|
|
@@ -46,9 +79,32 @@ export var createCeil = /* #__PURE__ */factory(name, dependencies, function (_re
|
|
|
46
79
|
return ceilNumber(x);
|
|
47
80
|
}
|
|
48
81
|
},
|
|
82
|
+
'number, number': function numberNumber(x, n) {
|
|
83
|
+
if (nearlyEqual(x, round(x, n), config.epsilon)) {
|
|
84
|
+
return round(x, n);
|
|
85
|
+
} else {
|
|
86
|
+
var _$split = "".concat(x, "e").split('e'),
|
|
87
|
+
_$split2 = _slicedToArray(_$split, 2),
|
|
88
|
+
number = _$split2[0],
|
|
89
|
+
exponent = _$split2[1];
|
|
90
|
+
|
|
91
|
+
var result = Math.ceil(Number("".concat(number, "e").concat(Number(exponent) + n)));
|
|
92
|
+
|
|
93
|
+
var _$split3 = "".concat(result, "e").split('e');
|
|
94
|
+
|
|
95
|
+
var _$split4 = _slicedToArray(_$split3, 2);
|
|
96
|
+
|
|
97
|
+
number = _$split4[0];
|
|
98
|
+
exponent = _$split4[1];
|
|
99
|
+
return Number("".concat(number, "e").concat(Number(exponent) - n));
|
|
100
|
+
}
|
|
101
|
+
},
|
|
49
102
|
Complex: function Complex(x) {
|
|
50
103
|
return x.ceil();
|
|
51
104
|
},
|
|
105
|
+
'Complex, number': function ComplexNumber(x, n) {
|
|
106
|
+
return x.ceil(n);
|
|
107
|
+
},
|
|
52
108
|
BigNumber: function BigNumber(x) {
|
|
53
109
|
if (bigNearlyEqual(x, round(x), config.epsilon)) {
|
|
54
110
|
return round(x);
|
|
@@ -56,12 +112,40 @@ export var createCeil = /* #__PURE__ */factory(name, dependencies, function (_re
|
|
|
56
112
|
return x.ceil();
|
|
57
113
|
}
|
|
58
114
|
},
|
|
115
|
+
'BigNumber, BigNumber': function BigNumberBigNumber(x, n) {
|
|
116
|
+
if (bigNearlyEqual(x, round(x, n), config.epsilon)) {
|
|
117
|
+
return round(x, n);
|
|
118
|
+
} else {
|
|
119
|
+
return x.toDecimalPlaces(n.toNumber(), Decimal.ROUND_CEIL);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
59
122
|
Fraction: function Fraction(x) {
|
|
60
123
|
return x.ceil();
|
|
61
124
|
},
|
|
125
|
+
'Fraction, number': function FractionNumber(x, n) {
|
|
126
|
+
return x.ceil(n);
|
|
127
|
+
},
|
|
62
128
|
'Array | Matrix': function ArrayMatrix(x) {
|
|
63
129
|
// deep map collection, skip zeros since ceil(0) = 0
|
|
64
130
|
return deepMap(x, this, true);
|
|
131
|
+
},
|
|
132
|
+
'Array | Matrix, number': function ArrayMatrixNumber(x, n) {
|
|
133
|
+
var _this = this;
|
|
134
|
+
|
|
135
|
+
// deep map collection, skip zeros since ceil(0) = 0
|
|
136
|
+
return deepMap(x, function (i) {
|
|
137
|
+
return _this(i, n);
|
|
138
|
+
}, true);
|
|
139
|
+
},
|
|
140
|
+
'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
|
141
|
+
return algorithm11(x, y, this, false);
|
|
142
|
+
},
|
|
143
|
+
'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
|
144
|
+
return algorithm14(x, y, this, false);
|
|
145
|
+
},
|
|
146
|
+
'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
|
|
147
|
+
// use matrix implementation
|
|
148
|
+
return algorithm14(matrix(y), x, this, true).valueOf();
|
|
65
149
|
}
|
|
66
150
|
});
|
|
67
151
|
});
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { factory } from '../../utils/factory';
|
|
2
2
|
import { deepMap } from '../../utils/collection';
|
|
3
|
+
import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14';
|
|
3
4
|
var name = 'fix';
|
|
4
|
-
var dependencies = ['typed', 'Complex', 'ceil', 'floor'];
|
|
5
|
+
var dependencies = ['typed', 'Complex', 'matrix', 'ceil', 'floor'];
|
|
5
6
|
export var createFix = /* #__PURE__ */factory(name, dependencies, function (_ref) {
|
|
6
7
|
var typed = _ref.typed,
|
|
7
8
|
_Complex = _ref.Complex,
|
|
9
|
+
matrix = _ref.matrix,
|
|
8
10
|
ceil = _ref.ceil,
|
|
9
11
|
floor = _ref.floor;
|
|
10
|
-
|
|
12
|
+
var algorithm14 = createAlgorithm14({
|
|
13
|
+
typed: typed
|
|
14
|
+
});
|
|
11
15
|
/**
|
|
12
16
|
* Round a value towards zero.
|
|
13
17
|
* For matrices, the function is evaluated element wise.
|
|
@@ -23,34 +27,67 @@ export var createFix = /* #__PURE__ */factory(name, dependencies, function (_ref
|
|
|
23
27
|
* math.fix(-4.2) // returns number -4
|
|
24
28
|
* math.fix(-4.7) // returns number -4
|
|
25
29
|
*
|
|
26
|
-
*
|
|
30
|
+
* math.fix(3.12, 1) // returns number 3.1
|
|
31
|
+
* math.fix(3.18, 1) // returns number 3.1
|
|
32
|
+
* math.fix(-4.12, 1) // returns number -4.1
|
|
33
|
+
* math.fix(-4.17, 1) // returns number -4.1
|
|
34
|
+
*
|
|
35
|
+
* const c = math.complex(3.22, -2.78)
|
|
27
36
|
* math.fix(c) // returns Complex 3 - 2i
|
|
37
|
+
* math.fix(c, 1) // returns Complex 3.2 - 2.7i
|
|
28
38
|
*
|
|
29
|
-
* math.fix([3.2, 3.8, -4.7])
|
|
39
|
+
* math.fix([3.2, 3.8, -4.7]) // returns Array [3, 3, -4]
|
|
40
|
+
* math.fix([3.2, 3.8, -4.7], 1) // returns Array [3.2, 3.8, -4.7]
|
|
30
41
|
*
|
|
31
42
|
* See also:
|
|
32
43
|
*
|
|
33
44
|
* ceil, floor, round
|
|
34
45
|
*
|
|
35
|
-
* @param
|
|
36
|
-
* @
|
|
46
|
+
* @param {number | BigNumber | Fraction | Complex | Array | Matrix} x Number to be rounded
|
|
47
|
+
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
|
48
|
+
* @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
|
|
37
49
|
*/
|
|
50
|
+
|
|
38
51
|
return typed('fix', {
|
|
39
52
|
number: function number(x) {
|
|
40
53
|
return x > 0 ? floor(x) : ceil(x);
|
|
41
54
|
},
|
|
55
|
+
'number, number | BigNumber': function numberNumberBigNumber(x, n) {
|
|
56
|
+
return x > 0 ? floor(x, n) : ceil(x, n);
|
|
57
|
+
},
|
|
42
58
|
Complex: function Complex(x) {
|
|
43
59
|
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));
|
|
44
60
|
},
|
|
61
|
+
'Complex, number | BigNumber': function ComplexNumberBigNumber(x, n) {
|
|
62
|
+
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));
|
|
63
|
+
},
|
|
45
64
|
BigNumber: function BigNumber(x) {
|
|
46
65
|
return x.isNegative() ? ceil(x) : floor(x);
|
|
47
66
|
},
|
|
67
|
+
'BigNumber, number | BigNumber': function BigNumberNumberBigNumber(x, n) {
|
|
68
|
+
return x.isNegative() ? ceil(x, n) : floor(x, n);
|
|
69
|
+
},
|
|
48
70
|
Fraction: function Fraction(x) {
|
|
49
71
|
return x.s < 0 ? x.ceil() : x.floor();
|
|
50
72
|
},
|
|
73
|
+
'Fraction, number | BigNumber': function FractionNumberBigNumber(x, n) {
|
|
74
|
+
return x.s < 0 ? x.ceil(n) : x.floor(n);
|
|
75
|
+
},
|
|
51
76
|
'Array | Matrix': function ArrayMatrix(x) {
|
|
52
77
|
// deep map collection, skip zeros since fix(0) = 0
|
|
53
78
|
return deepMap(x, this, true);
|
|
79
|
+
},
|
|
80
|
+
'Array | Matrix, number | BigNumber': function ArrayMatrixNumberBigNumber(x, n) {
|
|
81
|
+
var _this = this;
|
|
82
|
+
|
|
83
|
+
// deep map collection, skip zeros since fix(0) = 0
|
|
84
|
+
return deepMap(x, function (i) {
|
|
85
|
+
return _this(i, n);
|
|
86
|
+
}, true);
|
|
87
|
+
},
|
|
88
|
+
'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
|
|
89
|
+
// use matrix implementation
|
|
90
|
+
return algorithm14(matrix(y), x, this, true).valueOf();
|
|
54
91
|
}
|
|
55
92
|
});
|
|
56
93
|
});
|
|
@@ -1,14 +1,37 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
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."); }
|
|
4
|
+
|
|
5
|
+
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); }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import { Decimal } from 'decimal.js';
|
|
1
14
|
import { factory } from '../../utils/factory';
|
|
2
15
|
import { deepMap } from '../../utils/collection';
|
|
3
16
|
import { nearlyEqual } from '../../utils/number';
|
|
4
17
|
import { nearlyEqual as bigNearlyEqual } from '../../utils/bignumber/nearlyEqual';
|
|
18
|
+
import { createAlgorithm11 } from '../../type/matrix/utils/algorithm11';
|
|
19
|
+
import { createAlgorithm14 } from '../../type/matrix/utils/algorithm14';
|
|
5
20
|
var name = 'floor';
|
|
6
|
-
var dependencies = ['typed', 'config', 'round'];
|
|
21
|
+
var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar'];
|
|
7
22
|
export var createFloor = /* #__PURE__ */factory(name, dependencies, function (_ref) {
|
|
8
23
|
var typed = _ref.typed,
|
|
9
24
|
config = _ref.config,
|
|
10
|
-
round = _ref.round
|
|
11
|
-
|
|
25
|
+
round = _ref.round,
|
|
26
|
+
matrix = _ref.matrix,
|
|
27
|
+
equalScalar = _ref.equalScalar;
|
|
28
|
+
var algorithm11 = createAlgorithm11({
|
|
29
|
+
typed: typed,
|
|
30
|
+
equalScalar: equalScalar
|
|
31
|
+
});
|
|
32
|
+
var algorithm14 = createAlgorithm14({
|
|
33
|
+
typed: typed
|
|
34
|
+
});
|
|
12
35
|
/**
|
|
13
36
|
* Round a value towards minus infinity.
|
|
14
37
|
* For matrices, the function is evaluated element wise.
|
|
@@ -16,6 +39,7 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, function (_r
|
|
|
16
39
|
* Syntax:
|
|
17
40
|
*
|
|
18
41
|
* math.floor(x)
|
|
42
|
+
* math.floor(x, n)
|
|
19
43
|
*
|
|
20
44
|
* Examples:
|
|
21
45
|
*
|
|
@@ -24,18 +48,27 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, function (_r
|
|
|
24
48
|
* math.floor(-4.2) // returns number -5
|
|
25
49
|
* math.floor(-4.7) // returns number -5
|
|
26
50
|
*
|
|
27
|
-
*
|
|
28
|
-
* math.floor(
|
|
51
|
+
* math.floor(3.212, 2) // returns number 3.21
|
|
52
|
+
* math.floor(3.288, 2) // returns number 3.28
|
|
53
|
+
* math.floor(-4.212, 2) // returns number -4.22
|
|
54
|
+
* math.floor(-4.782, 2) // returns number -4.79
|
|
29
55
|
*
|
|
30
|
-
* math.
|
|
56
|
+
* const c = math.complex(3.24, -2.71)
|
|
57
|
+
* math.floor(c) // returns Complex 3 - 3i
|
|
58
|
+
* math.floor(c, 1) // returns Complex 3.2 - 2.8i
|
|
59
|
+
*
|
|
60
|
+
* math.floor([3.2, 3.8, -4.7]) // returns Array [3, 3, -5]
|
|
61
|
+
* math.floor([3.21, 3.82, -4.71], 1) // returns Array [3.2, 3.8, -4.8]
|
|
31
62
|
*
|
|
32
63
|
* See also:
|
|
33
64
|
*
|
|
34
65
|
* ceil, fix, round
|
|
35
66
|
*
|
|
36
67
|
* @param {number | BigNumber | Fraction | Complex | Array | Matrix} x Number to be rounded
|
|
68
|
+
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
|
37
69
|
* @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
|
|
38
70
|
*/
|
|
71
|
+
|
|
39
72
|
return typed('floor', {
|
|
40
73
|
number: function number(x) {
|
|
41
74
|
if (nearlyEqual(x, round(x), config.epsilon)) {
|
|
@@ -44,9 +77,32 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, function (_r
|
|
|
44
77
|
return Math.floor(x);
|
|
45
78
|
}
|
|
46
79
|
},
|
|
80
|
+
'number, number': function numberNumber(x, n) {
|
|
81
|
+
if (nearlyEqual(x, round(x, n), config.epsilon)) {
|
|
82
|
+
return round(x, n);
|
|
83
|
+
} else {
|
|
84
|
+
var _$split = "".concat(x, "e").split('e'),
|
|
85
|
+
_$split2 = _slicedToArray(_$split, 2),
|
|
86
|
+
number = _$split2[0],
|
|
87
|
+
exponent = _$split2[1];
|
|
88
|
+
|
|
89
|
+
var result = Math.floor(Number("".concat(number, "e").concat(Number(exponent) + n)));
|
|
90
|
+
|
|
91
|
+
var _$split3 = "".concat(result, "e").split('e');
|
|
92
|
+
|
|
93
|
+
var _$split4 = _slicedToArray(_$split3, 2);
|
|
94
|
+
|
|
95
|
+
number = _$split4[0];
|
|
96
|
+
exponent = _$split4[1];
|
|
97
|
+
return Number("".concat(number, "e").concat(Number(exponent) - n));
|
|
98
|
+
}
|
|
99
|
+
},
|
|
47
100
|
Complex: function Complex(x) {
|
|
48
101
|
return x.floor();
|
|
49
102
|
},
|
|
103
|
+
'Complex, number': function ComplexNumber(x, n) {
|
|
104
|
+
return x.floor(n);
|
|
105
|
+
},
|
|
50
106
|
BigNumber: function BigNumber(x) {
|
|
51
107
|
if (bigNearlyEqual(x, round(x), config.epsilon)) {
|
|
52
108
|
return round(x);
|
|
@@ -54,12 +110,40 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, function (_r
|
|
|
54
110
|
return x.floor();
|
|
55
111
|
}
|
|
56
112
|
},
|
|
113
|
+
'BigNumber, BigNumber': function BigNumberBigNumber(x, n) {
|
|
114
|
+
if (bigNearlyEqual(x, round(x, n), config.epsilon)) {
|
|
115
|
+
return round(x, n);
|
|
116
|
+
} else {
|
|
117
|
+
return x.toDecimalPlaces(n.toNumber(), Decimal.ROUND_FLOOR);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
57
120
|
Fraction: function Fraction(x) {
|
|
58
121
|
return x.floor();
|
|
59
122
|
},
|
|
123
|
+
'Fraction, number': function FractionNumber(x, n) {
|
|
124
|
+
return x.floor(n);
|
|
125
|
+
},
|
|
60
126
|
'Array | Matrix': function ArrayMatrix(x) {
|
|
61
127
|
// deep map collection, skip zeros since floor(0) = 0
|
|
62
128
|
return deepMap(x, this, true);
|
|
129
|
+
},
|
|
130
|
+
'Array | Matrix, number': function ArrayMatrixNumber(x, n) {
|
|
131
|
+
var _this = this;
|
|
132
|
+
|
|
133
|
+
// deep map collection, skip zeros since ceil(0) = 0
|
|
134
|
+
return deepMap(x, function (i) {
|
|
135
|
+
return _this(i, n);
|
|
136
|
+
}, true);
|
|
137
|
+
},
|
|
138
|
+
'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
|
139
|
+
return algorithm11(x, y, this, false);
|
|
140
|
+
},
|
|
141
|
+
'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
|
142
|
+
return algorithm14(x, y, this, false);
|
|
143
|
+
},
|
|
144
|
+
'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
|
|
145
|
+
// use matrix implementation
|
|
146
|
+
return algorithm14(matrix(y), x, this, true).valueOf();
|
|
63
147
|
}
|
|
64
148
|
});
|
|
65
149
|
});
|
|
@@ -43,10 +43,14 @@ export var createRound = /* #__PURE__ */factory(name, dependencies, function (_r
|
|
|
43
43
|
*
|
|
44
44
|
* Examples:
|
|
45
45
|
*
|
|
46
|
-
* math.round(3.
|
|
47
|
-
* math.round(3.
|
|
46
|
+
* math.round(3.22) // returns number 3
|
|
47
|
+
* math.round(3.82) // returns number 4
|
|
48
48
|
* math.round(-4.2) // returns number -4
|
|
49
49
|
* math.round(-4.7) // returns number -5
|
|
50
|
+
* math.round(3.22, 1) // returns number 3.2
|
|
51
|
+
* math.round(3.88, 1) // returns number 3.8
|
|
52
|
+
* math.round(-4.21, 1) // returns number -4.2
|
|
53
|
+
* math.round(-4.71, 1) // returns number -4.7
|
|
50
54
|
* math.round(math.pi, 3) // returns number 3.142
|
|
51
55
|
* math.round(123.45678, 2) // returns number 123.46
|
|
52
56
|
*
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { factory } from '../../utils/factory';
|
|
2
|
+
import { arraySize } from '../../utils/array';
|
|
3
|
+
var name = 'rotate';
|
|
4
|
+
var dependencies = ['typed', 'multiply', 'rotationMatrix'];
|
|
5
|
+
export var createRotate = /* #__PURE__ */factory(name, dependencies, function (_ref) {
|
|
6
|
+
var typed = _ref.typed,
|
|
7
|
+
multiply = _ref.multiply,
|
|
8
|
+
rotationMatrix = _ref.rotationMatrix;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Rotate a vector of size 1x2 counter-clockwise by a given angle
|
|
12
|
+
* Rotate a vector of size 1x3 counter-clockwise by a given angle around the given axis
|
|
13
|
+
*
|
|
14
|
+
* Syntax:
|
|
15
|
+
*
|
|
16
|
+
* math.rotate(w, theta)
|
|
17
|
+
* math.rotate(w, theta, v)
|
|
18
|
+
*
|
|
19
|
+
* Examples:
|
|
20
|
+
*
|
|
21
|
+
* math.rotate([11, 12], math.pi / 2) // returns matrix([-12, 11])
|
|
22
|
+
* math.rotate(matrix([11, 12]), math.pi / 2) // returns matrix([-12, 11])
|
|
23
|
+
*
|
|
24
|
+
* math.rotate([1, 0, 0], unit('90deg'), [0, 0, 1]) // returns matrix([0, 1, 0])
|
|
25
|
+
* math.rotate(matrix([1, 0, 0]), unit('90deg'), [0, 0, 1]) // returns matrix([0, 1, 0])
|
|
26
|
+
*
|
|
27
|
+
* math.rotate([1, 0], math.complex(1 + i)) // returns matrix([cos(1 + i) - sin(1 + i), sin(1 + i) + cos(1 + i)])
|
|
28
|
+
*
|
|
29
|
+
* See also:
|
|
30
|
+
*
|
|
31
|
+
* matrix, rotationMatrix
|
|
32
|
+
*
|
|
33
|
+
* @param {Array | Matrix} w Vector to rotate
|
|
34
|
+
* @param {number | BigNumber | Complex | Unit} theta Rotation angle
|
|
35
|
+
* @param {Array | Matrix} [v] Rotation axis
|
|
36
|
+
* @return {Array | Matrix} Multiplication of the rotation matrix and w
|
|
37
|
+
*/
|
|
38
|
+
return typed(name, {
|
|
39
|
+
'Array , number | BigNumber | Complex | Unit': function ArrayNumberBigNumberComplexUnit(w, theta) {
|
|
40
|
+
_validateSize(w, 2);
|
|
41
|
+
|
|
42
|
+
var matrixRes = multiply(rotationMatrix(theta), w);
|
|
43
|
+
return matrixRes.toArray();
|
|
44
|
+
},
|
|
45
|
+
'Matrix , number | BigNumber | Complex | Unit': function MatrixNumberBigNumberComplexUnit(w, theta) {
|
|
46
|
+
_validateSize(w, 2);
|
|
47
|
+
|
|
48
|
+
return multiply(rotationMatrix(theta), w);
|
|
49
|
+
},
|
|
50
|
+
'Array, number | BigNumber | Complex | Unit, Array | Matrix': function ArrayNumberBigNumberComplexUnitArrayMatrix(w, theta, v) {
|
|
51
|
+
_validateSize(w, 3);
|
|
52
|
+
|
|
53
|
+
var matrixRes = multiply(rotationMatrix(theta, v), w);
|
|
54
|
+
return matrixRes;
|
|
55
|
+
},
|
|
56
|
+
'Matrix, number | BigNumber | Complex | Unit, Array | Matrix': function MatrixNumberBigNumberComplexUnitArrayMatrix(w, theta, v) {
|
|
57
|
+
_validateSize(w, 3);
|
|
58
|
+
|
|
59
|
+
return multiply(rotationMatrix(theta, v), w);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
function _validateSize(v, expectedSize) {
|
|
64
|
+
var actualSize = Array.isArray(v) ? arraySize(v) : v.size();
|
|
65
|
+
|
|
66
|
+
if (actualSize.length > 2) {
|
|
67
|
+
throw new RangeError("Vector must be of dimensions 1x".concat(expectedSize));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (actualSize.length === 2 && actualSize[1] !== 1) {
|
|
71
|
+
throw new RangeError("Vector must be of dimensions 1x".concat(expectedSize));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (actualSize[0] !== expectedSize) {
|
|
75
|
+
throw new RangeError("Vector must be of dimensions 1x".concat(expectedSize));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|