mathjs 10.5.0 → 10.5.1
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +12 -0
- package/docs/datatypes/matrices.md +17 -0
- package/docs/expressions/syntax.md +4 -1
- package/docs/reference/functions/fix.md +1 -0
- package/docs/reference/functions/floor.md +4 -0
- package/docs/reference/functions/resolve.md +2 -2
- package/docs/reference/functions/simplifyConstant.md +52 -0
- package/lib/browser/math.js +5 -5
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesCeil.generated.js +6 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesFix.generated.js +9 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesFloor.generated.js +6 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesIndexNode.generated.js +0 -3
- package/lib/cjs/entry/dependenciesNumber/dependenciesCeil.generated.js +3 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesFix.generated.js +6 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesFloor.generated.js +3 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesIndexNode.generated.js +0 -3
- package/lib/cjs/entry/impureFunctionsAny.generated.js +0 -1
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +6 -7
- package/lib/cjs/entry/pureFunctionsAny.generated.js +10 -3
- package/lib/cjs/entry/pureFunctionsNumber.generated.js +21 -15
- package/lib/cjs/expression/node/IndexNode.js +26 -61
- package/lib/cjs/factoriesNumber.js +29 -24
- package/lib/cjs/function/algebra/resolve.js +3 -3
- package/lib/cjs/function/arithmetic/ceil.js +75 -39
- package/lib/cjs/function/arithmetic/fix.js +54 -16
- package/lib/cjs/function/arithmetic/floor.js +79 -37
- package/lib/cjs/function/arithmetic/nthRoot.js +1 -3
- package/lib/cjs/function/arithmetic/round.js +27 -47
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/plain/number/arithmetic.js +9 -27
- package/lib/cjs/type/matrix/function/sparse.js +6 -0
- package/lib/cjs/utils/lruQueue.js +1 -3
- package/lib/cjs/utils/object.js +3 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesCeil.generated.js +4 -0
- package/lib/esm/entry/dependenciesAny/dependenciesFix.generated.js +6 -0
- package/lib/esm/entry/dependenciesAny/dependenciesFloor.generated.js +4 -0
- package/lib/esm/entry/dependenciesAny/dependenciesIndexNode.generated.js +0 -2
- package/lib/esm/entry/dependenciesNumber/dependenciesCeil.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesFix.generated.js +4 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesFloor.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesIndexNode.generated.js +0 -2
- package/lib/esm/entry/impureFunctionsAny.generated.js +0 -1
- package/lib/esm/entry/impureFunctionsNumber.generated.js +7 -8
- package/lib/esm/entry/pureFunctionsAny.generated.js +10 -3
- package/lib/esm/entry/pureFunctionsNumber.generated.js +16 -10
- package/lib/esm/expression/node/BlockNode.js +3 -3
- package/lib/esm/expression/node/IndexNode.js +22 -59
- package/lib/esm/expression/parse.js +5 -5
- package/lib/esm/factoriesNumber.js +6 -6
- package/lib/esm/function/algebra/decomposition/qr.js +2 -2
- package/lib/esm/function/algebra/resolve.js +3 -3
- package/lib/esm/function/algebra/solver/utils/solveValidation.js +5 -5
- package/lib/esm/function/algebra/sparse/csChol.js +2 -2
- package/lib/esm/function/algebra/sparse/csLeaf.js +2 -2
- package/lib/esm/function/algebra/sparse/csLu.js +3 -3
- package/lib/esm/function/arithmetic/ceil.js +61 -24
- package/lib/esm/function/arithmetic/fix.js +51 -13
- package/lib/esm/function/arithmetic/floor.js +65 -23
- package/lib/esm/function/arithmetic/nthRoot.js +1 -3
- package/lib/esm/function/arithmetic/nthRoots.js +1 -1
- package/lib/esm/function/arithmetic/round.js +25 -43
- package/lib/esm/function/matrix/expm.js +2 -2
- package/lib/esm/function/probability/gamma.js +1 -1
- package/lib/esm/function/string/bin.js +1 -1
- package/lib/esm/function/string/hex.js +1 -1
- package/lib/esm/function/string/oct.js +1 -1
- package/lib/esm/plain/number/arithmetic.js +9 -17
- package/lib/esm/type/complex/Complex.js +2 -2
- package/lib/esm/type/matrix/DenseMatrix.js +2 -2
- package/lib/esm/type/matrix/FibonacciHeap.js +2 -2
- package/lib/esm/type/matrix/SparseMatrix.js +13 -13
- package/lib/esm/type/matrix/function/sparse.js +6 -0
- package/lib/esm/type/unit/Unit.js +7 -7
- package/lib/esm/utils/lruQueue.js +1 -2
- package/lib/esm/utils/number.js +3 -3
- package/lib/esm/utils/object.js +3 -1
- package/lib/esm/version.js +1 -1
- package/package.json +14 -3
- package/types/index.d.ts +1794 -1372
- package/types/index.ts +697 -266
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
6
6
|
value: true
|
7
7
|
});
|
8
|
-
exports.createCeil = void 0;
|
8
|
+
exports.createCeilNumber = exports.createCeil = void 0;
|
9
9
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
11
11
|
|
@@ -19,27 +19,73 @@ var _number = require("../../utils/number.js");
|
|
19
19
|
|
20
20
|
var _nearlyEqual = require("../../utils/bignumber/nearlyEqual.js");
|
21
21
|
|
22
|
-
var _index = require("../../plain/number/index.js");
|
23
|
-
|
24
22
|
var _algorithm = require("../../type/matrix/utils/algorithm11.js");
|
25
23
|
|
26
|
-
var _algorithm2 = require("../../type/matrix/utils/
|
24
|
+
var _algorithm2 = require("../../type/matrix/utils/algorithm12.js");
|
25
|
+
|
26
|
+
var _algorithm3 = require("../../type/matrix/utils/algorithm14.js");
|
27
27
|
|
28
28
|
var name = 'ceil';
|
29
|
-
var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar'];
|
30
|
-
var
|
29
|
+
var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar', 'zeros', 'DenseMatrix'];
|
30
|
+
var createCeilNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config', 'round'], function (_ref) {
|
31
31
|
var typed = _ref.typed,
|
32
32
|
config = _ref.config,
|
33
|
-
round = _ref.round
|
34
|
-
|
35
|
-
|
33
|
+
round = _ref.round;
|
34
|
+
return typed(name, {
|
35
|
+
number: function number(x) {
|
36
|
+
if ((0, _number.nearlyEqual)(x, round(x), config.epsilon)) {
|
37
|
+
return round(x);
|
38
|
+
} else {
|
39
|
+
return Math.ceil(x);
|
40
|
+
}
|
41
|
+
},
|
42
|
+
'number, number': function numberNumber(x, n) {
|
43
|
+
if ((0, _number.nearlyEqual)(x, round(x, n), config.epsilon)) {
|
44
|
+
return round(x, n);
|
45
|
+
} else {
|
46
|
+
var _$split = "".concat(x, "e").split('e'),
|
47
|
+
_$split2 = (0, _slicedToArray2.default)(_$split, 2),
|
48
|
+
number = _$split2[0],
|
49
|
+
exponent = _$split2[1];
|
50
|
+
|
51
|
+
var result = Math.ceil(Number("".concat(number, "e").concat(Number(exponent) + n)));
|
52
|
+
|
53
|
+
var _$split3 = "".concat(result, "e").split('e');
|
54
|
+
|
55
|
+
var _$split4 = (0, _slicedToArray2.default)(_$split3, 2);
|
56
|
+
|
57
|
+
number = _$split4[0];
|
58
|
+
exponent = _$split4[1];
|
59
|
+
return Number("".concat(number, "e").concat(Number(exponent) - n));
|
60
|
+
}
|
61
|
+
}
|
62
|
+
});
|
63
|
+
});
|
64
|
+
exports.createCeilNumber = createCeilNumber;
|
65
|
+
var createCeil = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref2) {
|
66
|
+
var typed = _ref2.typed,
|
67
|
+
config = _ref2.config,
|
68
|
+
round = _ref2.round,
|
69
|
+
matrix = _ref2.matrix,
|
70
|
+
equalScalar = _ref2.equalScalar,
|
71
|
+
zeros = _ref2.zeros,
|
72
|
+
DenseMatrix = _ref2.DenseMatrix;
|
36
73
|
var algorithm11 = (0, _algorithm.createAlgorithm11)({
|
37
74
|
typed: typed,
|
38
75
|
equalScalar: equalScalar
|
39
76
|
});
|
40
|
-
var
|
77
|
+
var algorithm12 = (0, _algorithm2.createAlgorithm12)({
|
78
|
+
typed: typed,
|
79
|
+
DenseMatrix: DenseMatrix
|
80
|
+
});
|
81
|
+
var algorithm14 = (0, _algorithm3.createAlgorithm14)({
|
41
82
|
typed: typed
|
42
83
|
});
|
84
|
+
var ceilNumber = createCeilNumber({
|
85
|
+
typed: typed,
|
86
|
+
config: config,
|
87
|
+
round: round
|
88
|
+
});
|
43
89
|
/**
|
44
90
|
* Round a value towards plus infinity
|
45
91
|
* If `x` is complex, both real and imaginary part are rounded towards plus infinity.
|
@@ -79,39 +125,17 @@ var createCeil = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
79
125
|
*/
|
80
126
|
|
81
127
|
return typed('ceil', {
|
82
|
-
number:
|
83
|
-
|
84
|
-
return round(x);
|
85
|
-
} else {
|
86
|
-
return (0, _index.ceilNumber)(x);
|
87
|
-
}
|
88
|
-
},
|
89
|
-
'number, number': function numberNumber(x, n) {
|
90
|
-
if ((0, _number.nearlyEqual)(x, round(x, n), config.epsilon)) {
|
91
|
-
return round(x, n);
|
92
|
-
} else {
|
93
|
-
var _$split = "".concat(x, "e").split('e'),
|
94
|
-
_$split2 = (0, _slicedToArray2.default)(_$split, 2),
|
95
|
-
number = _$split2[0],
|
96
|
-
exponent = _$split2[1];
|
97
|
-
|
98
|
-
var result = Math.ceil(Number("".concat(number, "e").concat(Number(exponent) + n)));
|
99
|
-
|
100
|
-
var _$split3 = "".concat(result, "e").split('e');
|
101
|
-
|
102
|
-
var _$split4 = (0, _slicedToArray2.default)(_$split3, 2);
|
103
|
-
|
104
|
-
number = _$split4[0];
|
105
|
-
exponent = _$split4[1];
|
106
|
-
return Number("".concat(number, "e").concat(Number(exponent) - n));
|
107
|
-
}
|
108
|
-
},
|
128
|
+
number: ceilNumber.signatures.number,
|
129
|
+
'number,number': ceilNumber.signatures['number,number'],
|
109
130
|
Complex: function Complex(x) {
|
110
131
|
return x.ceil();
|
111
132
|
},
|
112
133
|
'Complex, number': function ComplexNumber(x, n) {
|
113
134
|
return x.ceil(n);
|
114
135
|
},
|
136
|
+
'Complex, BigNumber': function ComplexBigNumber(x, n) {
|
137
|
+
return x.ceil(n.toNumber());
|
138
|
+
},
|
115
139
|
BigNumber: function BigNumber(x) {
|
116
140
|
if ((0, _nearlyEqual.nearlyEqual)(x, round(x), config.epsilon)) {
|
117
141
|
return round(x);
|
@@ -132,11 +156,14 @@ var createCeil = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
132
156
|
'Fraction, number': function FractionNumber(x, n) {
|
133
157
|
return x.ceil(n);
|
134
158
|
},
|
159
|
+
'Fraction, BigNumber': function FractionBigNumber(x, n) {
|
160
|
+
return x.ceil(n.toNumber());
|
161
|
+
},
|
135
162
|
'Array | Matrix': function ArrayMatrix(x) {
|
136
163
|
// deep map collection, skip zeros since ceil(0) = 0
|
137
164
|
return (0, _collection.deepMap)(x, this, true);
|
138
165
|
},
|
139
|
-
'Array |
|
166
|
+
'Array, number | BigNumber': function ArrayNumberBigNumber(x, n) {
|
140
167
|
var _this = this;
|
141
168
|
|
142
169
|
// deep map collection, skip zeros since ceil(0) = 0
|
@@ -150,9 +177,18 @@ var createCeil = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
|
|
150
177
|
'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
151
178
|
return algorithm14(x, y, this, false);
|
152
179
|
},
|
153
|
-
'number | Complex | BigNumber, Array': function
|
180
|
+
'number | Complex | Fraction | BigNumber, Array': function numberComplexFractionBigNumberArray(x, y) {
|
154
181
|
// use matrix implementation
|
155
182
|
return algorithm14(matrix(y), x, this, true).valueOf();
|
183
|
+
},
|
184
|
+
'number | Complex | Fraction | BigNumber, Matrix': function numberComplexFractionBigNumberMatrix(x, y) {
|
185
|
+
if (equalScalar(x, 0)) return zeros(y.size(), y.storage());
|
186
|
+
|
187
|
+
if (y.storage() === 'dense') {
|
188
|
+
return algorithm14(y, x, this, true);
|
189
|
+
}
|
190
|
+
|
191
|
+
return algorithm12(y, x, this, true);
|
156
192
|
}
|
157
193
|
});
|
158
194
|
});
|
@@ -3,25 +3,53 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.createFix = void 0;
|
6
|
+
exports.createFixNumber = exports.createFix = void 0;
|
7
7
|
|
8
8
|
var _factory = require("../../utils/factory.js");
|
9
9
|
|
10
10
|
var _collection = require("../../utils/collection.js");
|
11
11
|
|
12
|
-
var _algorithm = require("../../type/matrix/utils/
|
12
|
+
var _algorithm = require("../../type/matrix/utils/algorithm12.js");
|
13
|
+
|
14
|
+
var _algorithm2 = require("../../type/matrix/utils/algorithm14.js");
|
13
15
|
|
14
16
|
var name = 'fix';
|
15
|
-
var dependencies = ['typed', 'Complex', 'matrix', 'ceil', 'floor'];
|
16
|
-
var
|
17
|
+
var dependencies = ['typed', 'Complex', 'matrix', 'ceil', 'floor', 'equalScalar', 'zeros', 'DenseMatrix'];
|
18
|
+
var createFixNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'ceil', 'floor'], function (_ref) {
|
17
19
|
var typed = _ref.typed,
|
18
|
-
_Complex = _ref.Complex,
|
19
|
-
matrix = _ref.matrix,
|
20
20
|
ceil = _ref.ceil,
|
21
21
|
floor = _ref.floor;
|
22
|
-
|
22
|
+
return typed(name, {
|
23
|
+
number: function number(x) {
|
24
|
+
return x > 0 ? floor(x) : ceil(x);
|
25
|
+
},
|
26
|
+
'number, number': function numberNumber(x, n) {
|
27
|
+
return x > 0 ? floor(x, n) : ceil(x, n);
|
28
|
+
}
|
29
|
+
});
|
30
|
+
});
|
31
|
+
exports.createFixNumber = createFixNumber;
|
32
|
+
var createFix = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref2) {
|
33
|
+
var typed = _ref2.typed,
|
34
|
+
_Complex = _ref2.Complex,
|
35
|
+
matrix = _ref2.matrix,
|
36
|
+
ceil = _ref2.ceil,
|
37
|
+
floor = _ref2.floor,
|
38
|
+
equalScalar = _ref2.equalScalar,
|
39
|
+
zeros = _ref2.zeros,
|
40
|
+
DenseMatrix = _ref2.DenseMatrix;
|
41
|
+
var algorithm12 = (0, _algorithm.createAlgorithm12)({
|
42
|
+
typed: typed,
|
43
|
+
DenseMatrix: DenseMatrix
|
44
|
+
});
|
45
|
+
var algorithm14 = (0, _algorithm2.createAlgorithm14)({
|
23
46
|
typed: typed
|
24
47
|
});
|
48
|
+
var fixNumber = createFixNumber({
|
49
|
+
typed: typed,
|
50
|
+
ceil: ceil,
|
51
|
+
floor: floor
|
52
|
+
});
|
25
53
|
/**
|
26
54
|
* Round a value towards zero.
|
27
55
|
* For matrices, the function is evaluated element wise.
|
@@ -29,6 +57,7 @@ var createFix = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
|
|
29
57
|
* Syntax:
|
30
58
|
*
|
31
59
|
* math.fix(x)
|
60
|
+
* math.fix(x,n)
|
32
61
|
*
|
33
62
|
* Examples:
|
34
63
|
*
|
@@ -59,16 +88,16 @@ var createFix = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
|
|
59
88
|
*/
|
60
89
|
|
61
90
|
return typed('fix', {
|
62
|
-
number:
|
63
|
-
|
64
|
-
},
|
65
|
-
'number, number | BigNumber': function numberNumberBigNumber(x, n) {
|
66
|
-
return x > 0 ? floor(x, n) : ceil(x, n);
|
67
|
-
},
|
91
|
+
number: fixNumber.signatures.number,
|
92
|
+
'number, number | BigNumber': fixNumber.signatures['number,number'],
|
68
93
|
Complex: function Complex(x) {
|
69
94
|
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));
|
70
95
|
},
|
71
|
-
'Complex, number
|
96
|
+
'Complex, number': function ComplexNumber(x, n) {
|
97
|
+
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));
|
98
|
+
},
|
99
|
+
'Complex, BigNumber': function ComplexBigNumber(x, bn) {
|
100
|
+
var n = bn.toNumber();
|
72
101
|
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
102
|
},
|
74
103
|
BigNumber: function BigNumber(x) {
|
@@ -81,7 +110,7 @@ var createFix = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
|
|
81
110
|
return x.s < 0 ? x.ceil() : x.floor();
|
82
111
|
},
|
83
112
|
'Fraction, number | BigNumber': function FractionNumberBigNumber(x, n) {
|
84
|
-
return x.s < 0 ?
|
113
|
+
return x.s < 0 ? ceil(x, n) : floor(x, n);
|
85
114
|
},
|
86
115
|
'Array | Matrix': function ArrayMatrix(x) {
|
87
116
|
// deep map collection, skip zeros since fix(0) = 0
|
@@ -95,9 +124,18 @@ var createFix = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
|
|
95
124
|
return _this(i, n);
|
96
125
|
}, true);
|
97
126
|
},
|
98
|
-
'number | Complex | BigNumber, Array': function
|
127
|
+
'number | Complex | Fraction | BigNumber, Array': function numberComplexFractionBigNumberArray(x, y) {
|
99
128
|
// use matrix implementation
|
100
129
|
return algorithm14(matrix(y), x, this, true).valueOf();
|
130
|
+
},
|
131
|
+
'number | Complex | Fraction | BigNumber, Matrix': function numberComplexFractionBigNumberMatrix(x, y) {
|
132
|
+
if (equalScalar(x, 0)) return zeros(y.size(), y.storage());
|
133
|
+
|
134
|
+
if (y.storage() === 'dense') {
|
135
|
+
return algorithm14(y, x, this, true);
|
136
|
+
}
|
137
|
+
|
138
|
+
return algorithm12(y, x, this, true);
|
101
139
|
}
|
102
140
|
});
|
103
141
|
});
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
6
6
|
value: true
|
7
7
|
});
|
8
|
-
exports.createFloor = void 0;
|
8
|
+
exports.createFloorNumber = exports.createFloor = void 0;
|
9
9
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
11
11
|
|
@@ -21,23 +21,71 @@ var _nearlyEqual = require("../../utils/bignumber/nearlyEqual.js");
|
|
21
21
|
|
22
22
|
var _algorithm = require("../../type/matrix/utils/algorithm11.js");
|
23
23
|
|
24
|
-
var _algorithm2 = require("../../type/matrix/utils/
|
24
|
+
var _algorithm2 = require("../../type/matrix/utils/algorithm12.js");
|
25
|
+
|
26
|
+
var _algorithm3 = require("../../type/matrix/utils/algorithm14.js");
|
25
27
|
|
26
28
|
var name = 'floor';
|
27
|
-
var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar'];
|
28
|
-
var
|
29
|
+
var dependencies = ['typed', 'config', 'round', 'matrix', 'equalScalar', 'zeros', 'DenseMatrix'];
|
30
|
+
var createFloorNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed', 'config', 'round'], function (_ref) {
|
29
31
|
var typed = _ref.typed,
|
30
32
|
config = _ref.config,
|
31
|
-
round = _ref.round
|
32
|
-
|
33
|
-
|
33
|
+
round = _ref.round;
|
34
|
+
return typed(name, {
|
35
|
+
number: function number(x) {
|
36
|
+
if ((0, _number.nearlyEqual)(x, round(x), config.epsilon)) {
|
37
|
+
return round(x);
|
38
|
+
} else {
|
39
|
+
return Math.floor(x);
|
40
|
+
}
|
41
|
+
},
|
42
|
+
'number, number': function numberNumber(x, n) {
|
43
|
+
if ((0, _number.nearlyEqual)(x, round(x, n), config.epsilon)) {
|
44
|
+
return round(x, n);
|
45
|
+
} else {
|
46
|
+
var _$split = "".concat(x, "e").split('e'),
|
47
|
+
_$split2 = (0, _slicedToArray2.default)(_$split, 2),
|
48
|
+
number = _$split2[0],
|
49
|
+
exponent = _$split2[1];
|
50
|
+
|
51
|
+
var result = Math.floor(Number("".concat(number, "e").concat(Number(exponent) + n)));
|
52
|
+
|
53
|
+
var _$split3 = "".concat(result, "e").split('e');
|
54
|
+
|
55
|
+
var _$split4 = (0, _slicedToArray2.default)(_$split3, 2);
|
56
|
+
|
57
|
+
number = _$split4[0];
|
58
|
+
exponent = _$split4[1];
|
59
|
+
return Number("".concat(number, "e").concat(Number(exponent) - n));
|
60
|
+
}
|
61
|
+
}
|
62
|
+
});
|
63
|
+
});
|
64
|
+
exports.createFloorNumber = createFloorNumber;
|
65
|
+
var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref2) {
|
66
|
+
var typed = _ref2.typed,
|
67
|
+
config = _ref2.config,
|
68
|
+
round = _ref2.round,
|
69
|
+
matrix = _ref2.matrix,
|
70
|
+
equalScalar = _ref2.equalScalar,
|
71
|
+
zeros = _ref2.zeros,
|
72
|
+
DenseMatrix = _ref2.DenseMatrix;
|
34
73
|
var algorithm11 = (0, _algorithm.createAlgorithm11)({
|
35
74
|
typed: typed,
|
36
75
|
equalScalar: equalScalar
|
37
76
|
});
|
38
|
-
var
|
77
|
+
var algorithm12 = (0, _algorithm2.createAlgorithm12)({
|
78
|
+
typed: typed,
|
79
|
+
DenseMatrix: DenseMatrix
|
80
|
+
});
|
81
|
+
var algorithm14 = (0, _algorithm3.createAlgorithm14)({
|
39
82
|
typed: typed
|
40
83
|
});
|
84
|
+
var floorNumber = createFloorNumber({
|
85
|
+
typed: typed,
|
86
|
+
config: config,
|
87
|
+
round: round
|
88
|
+
});
|
41
89
|
/**
|
42
90
|
* Round a value towards minus infinity.
|
43
91
|
* For matrices, the function is evaluated element wise.
|
@@ -66,6 +114,10 @@ var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
66
114
|
* math.floor([3.2, 3.8, -4.7]) // returns Array [3, 3, -5]
|
67
115
|
* math.floor([3.21, 3.82, -4.71], 1) // returns Array [3.2, 3.8, -4.8]
|
68
116
|
*
|
117
|
+
* math.floor(math.tau, [2, 3]) // returns Array [6.28, 6.283]
|
118
|
+
*
|
119
|
+
* // Note that floor(array, array) currently not implemented.
|
120
|
+
*
|
69
121
|
* See also:
|
70
122
|
*
|
71
123
|
* ceil, fix, round
|
@@ -76,39 +128,17 @@ var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
76
128
|
*/
|
77
129
|
|
78
130
|
return typed('floor', {
|
79
|
-
number:
|
80
|
-
|
81
|
-
return round(x);
|
82
|
-
} else {
|
83
|
-
return Math.floor(x);
|
84
|
-
}
|
85
|
-
},
|
86
|
-
'number, number': function numberNumber(x, n) {
|
87
|
-
if ((0, _number.nearlyEqual)(x, round(x, n), config.epsilon)) {
|
88
|
-
return round(x, n);
|
89
|
-
} else {
|
90
|
-
var _$split = "".concat(x, "e").split('e'),
|
91
|
-
_$split2 = (0, _slicedToArray2.default)(_$split, 2),
|
92
|
-
number = _$split2[0],
|
93
|
-
exponent = _$split2[1];
|
94
|
-
|
95
|
-
var result = Math.floor(Number("".concat(number, "e").concat(Number(exponent) + n)));
|
96
|
-
|
97
|
-
var _$split3 = "".concat(result, "e").split('e');
|
98
|
-
|
99
|
-
var _$split4 = (0, _slicedToArray2.default)(_$split3, 2);
|
100
|
-
|
101
|
-
number = _$split4[0];
|
102
|
-
exponent = _$split4[1];
|
103
|
-
return Number("".concat(number, "e").concat(Number(exponent) - n));
|
104
|
-
}
|
105
|
-
},
|
131
|
+
number: floorNumber.signatures.number,
|
132
|
+
'number,number': floorNumber.signatures['number,number'],
|
106
133
|
Complex: function Complex(x) {
|
107
134
|
return x.floor();
|
108
135
|
},
|
109
136
|
'Complex, number': function ComplexNumber(x, n) {
|
110
137
|
return x.floor(n);
|
111
138
|
},
|
139
|
+
'Complex, BigNumber': function ComplexBigNumber(x, n) {
|
140
|
+
return x.floor(n.toNumber());
|
141
|
+
},
|
112
142
|
BigNumber: function BigNumber(x) {
|
113
143
|
if ((0, _nearlyEqual.nearlyEqual)(x, round(x), config.epsilon)) {
|
114
144
|
return round(x);
|
@@ -129,11 +159,14 @@ var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
129
159
|
'Fraction, number': function FractionNumber(x, n) {
|
130
160
|
return x.floor(n);
|
131
161
|
},
|
162
|
+
'Fraction, BigNumber': function FractionBigNumber(x, n) {
|
163
|
+
return x.floor(n.toNumber());
|
164
|
+
},
|
132
165
|
'Array | Matrix': function ArrayMatrix(x) {
|
133
166
|
// deep map collection, skip zeros since floor(0) = 0
|
134
167
|
return (0, _collection.deepMap)(x, this, true);
|
135
168
|
},
|
136
|
-
'Array |
|
169
|
+
'Array, number | BigNumber': function ArrayNumberBigNumber(x, n) {
|
137
170
|
var _this = this;
|
138
171
|
|
139
172
|
// deep map collection, skip zeros since ceil(0) = 0
|
@@ -147,9 +180,18 @@ var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
147
180
|
'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
148
181
|
return algorithm14(x, y, this, false);
|
149
182
|
},
|
150
|
-
'number | Complex | BigNumber, Array': function
|
183
|
+
'number | Complex | Fraction | BigNumber, Array': function numberComplexFractionBigNumberArray(x, y) {
|
151
184
|
// use matrix implementation
|
152
185
|
return algorithm14(matrix(y), x, this, true).valueOf();
|
186
|
+
},
|
187
|
+
'number | Complex | Fraction | BigNumber, Matrix': function numberComplexFractionBigNumberMatrix(x, y) {
|
188
|
+
if (equalScalar(x, 0)) return zeros(y.size(), y.storage());
|
189
|
+
|
190
|
+
if (y.storage() === 'dense') {
|
191
|
+
return algorithm14(y, x, this, true);
|
192
|
+
}
|
193
|
+
|
194
|
+
return algorithm12(y, x, this, true);
|
153
195
|
}
|
154
196
|
});
|
155
197
|
});
|
@@ -81,9 +81,7 @@ var createNthRoot = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fun
|
|
81
81
|
|
82
82
|
var complexErr = '' + 'Complex number not supported in function nthRoot. ' + 'Use nthRoots instead.';
|
83
83
|
return typed(name, {
|
84
|
-
number:
|
85
|
-
return (0, _index.nthRootNumber)(x, 2);
|
86
|
-
},
|
84
|
+
number: _index.nthRootNumber,
|
87
85
|
'number, number': _index.nthRootNumber,
|
88
86
|
BigNumber: function BigNumber(x) {
|
89
87
|
return _bigNthRoot(x, new _BigNumber(2));
|
@@ -1,20 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
6
4
|
value: true
|
7
5
|
});
|
8
|
-
exports.
|
9
|
-
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
6
|
+
exports.createRound = void 0;
|
11
7
|
|
12
8
|
var _factory = require("../../utils/factory.js");
|
13
9
|
|
14
10
|
var _collection = require("../../utils/collection.js");
|
15
11
|
|
16
|
-
var _number = require("../../utils/number.js");
|
17
|
-
|
18
12
|
var _algorithm = require("../../type/matrix/utils/algorithm11.js");
|
19
13
|
|
20
14
|
var _algorithm2 = require("../../type/matrix/utils/algorithm12.js");
|
@@ -23,10 +17,6 @@ var _algorithm3 = require("../../type/matrix/utils/algorithm14.js");
|
|
23
17
|
|
24
18
|
var _index = require("../../plain/number/index.js");
|
25
19
|
|
26
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
27
|
-
|
28
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
29
|
-
|
30
20
|
var NO_INT = 'Number of decimals in function round must be an integer';
|
31
21
|
var name = 'round';
|
32
22
|
var dependencies = ['typed', 'matrix', 'equalScalar', 'zeros', 'BigNumber', 'DenseMatrix'];
|
@@ -84,7 +74,16 @@ var createRound = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
84
74
|
* @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
|
85
75
|
*/
|
86
76
|
|
87
|
-
return typed(name,
|
77
|
+
return typed(name, {
|
78
|
+
number: _index.roundNumber,
|
79
|
+
'number, number': _index.roundNumber,
|
80
|
+
'number, BigNumber': function numberBigNumber(x, n) {
|
81
|
+
if (!n.isInteger()) {
|
82
|
+
throw new TypeError(NO_INT);
|
83
|
+
}
|
84
|
+
|
85
|
+
return new BigNumber(x).toDecimalPlaces(n.toNumber());
|
86
|
+
},
|
88
87
|
Complex: function Complex(x) {
|
89
88
|
return x.round();
|
90
89
|
},
|
@@ -104,13 +103,6 @@ var createRound = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
104
103
|
|
105
104
|
return x.round(_n);
|
106
105
|
},
|
107
|
-
'number, BigNumber': function numberBigNumber(x, n) {
|
108
|
-
if (!n.isInteger()) {
|
109
|
-
throw new TypeError(NO_INT);
|
110
|
-
}
|
111
|
-
|
112
|
-
return new BigNumber(x).toDecimalPlaces(n.toNumber());
|
113
|
-
},
|
114
106
|
BigNumber: function BigNumber(x) {
|
115
107
|
return x.toDecimalPlaces(0);
|
116
108
|
},
|
@@ -131,6 +123,13 @@ var createRound = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
131
123
|
|
132
124
|
return x.round(n);
|
133
125
|
},
|
126
|
+
'Fraction, BigNumber': function FractionBigNumber(x, n) {
|
127
|
+
if (!n.isInteger()) {
|
128
|
+
throw new TypeError(NO_INT);
|
129
|
+
}
|
130
|
+
|
131
|
+
return x.round(n.toNumber());
|
132
|
+
},
|
134
133
|
'Array | Matrix': function ArrayMatrix(x) {
|
135
134
|
// deep map collection, skip zeros since round(0) = 0
|
136
135
|
return (0, _collection.deepMap)(x, this, true);
|
@@ -141,7 +140,11 @@ var createRound = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
141
140
|
'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
142
141
|
return algorithm14(x, y, this, false);
|
143
142
|
},
|
144
|
-
'number |
|
143
|
+
'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
|
144
|
+
// use matrix implementation
|
145
|
+
return algorithm14(matrix(x), y, this, false).valueOf();
|
146
|
+
},
|
147
|
+
'number | Complex | BigNumber | Fraction, SparseMatrix': function numberComplexBigNumberFractionSparseMatrix(x, y) {
|
145
148
|
// check scalar is zero
|
146
149
|
if (equalScalar(x, 0)) {
|
147
150
|
// do not execute algorithm, result will be a zero matrix
|
@@ -150,7 +153,7 @@ var createRound = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
150
153
|
|
151
154
|
return algorithm12(y, x, this, true);
|
152
155
|
},
|
153
|
-
'number | Complex | BigNumber, DenseMatrix': function
|
156
|
+
'number | Complex | BigNumber | Fraction, DenseMatrix': function numberComplexBigNumberFractionDenseMatrix(x, y) {
|
154
157
|
// check scalar is zero
|
155
158
|
if (equalScalar(x, 0)) {
|
156
159
|
// do not execute algorithm, result will be a zero matrix
|
@@ -159,33 +162,10 @@ var createRound = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
159
162
|
|
160
163
|
return algorithm14(y, x, this, true);
|
161
164
|
},
|
162
|
-
'
|
163
|
-
// use matrix implementation
|
164
|
-
return algorithm14(matrix(x), y, this, false).valueOf();
|
165
|
-
},
|
166
|
-
'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
|
165
|
+
'number | Complex | BigNumber | Fraction, Array': function numberComplexBigNumberFractionArray(x, y) {
|
167
166
|
// use matrix implementation
|
168
167
|
return algorithm14(matrix(y), x, this, true).valueOf();
|
169
168
|
}
|
170
|
-
})
|
171
|
-
});
|
172
|
-
exports.createRound = createRound;
|
173
|
-
var roundNumberSignatures = {
|
174
|
-
number: _index.roundNumber,
|
175
|
-
'number, number': function numberNumber(x, n) {
|
176
|
-
if (!(0, _number.isInteger)(n)) {
|
177
|
-
throw new TypeError(NO_INT);
|
178
|
-
}
|
179
|
-
|
180
|
-
if (n < 0 || n > 15) {
|
181
|
-
throw new Error('Number of decimals in function round must be in the range of 0-15');
|
182
|
-
}
|
183
|
-
|
184
|
-
return (0, _index.roundNumber)(x, n);
|
185
|
-
}
|
186
|
-
};
|
187
|
-
var createRoundNumber = /* #__PURE__ */(0, _factory.factory)(name, ['typed'], function (_ref2) {
|
188
|
-
var typed = _ref2.typed;
|
189
|
-
return typed(name, roundNumberSignatures);
|
169
|
+
});
|
190
170
|
});
|
191
|
-
exports.
|
171
|
+
exports.createRound = createRound;
|
package/lib/cjs/header.js
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
* It features real and complex numbers, units, matrices, a large set of
|
7
7
|
* mathematical functions, and a flexible expression parser.
|
8
8
|
*
|
9
|
-
* @version 10.5.
|
10
|
-
* @date 2022-
|
9
|
+
* @version 10.5.1
|
10
|
+
* @date 2022-05-02
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2022 Jos de Jong <wjosdejong@gmail.com>
|