mathjs 13.2.2 → 14.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +26 -0
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +2 -10
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/core/function/import.js +4 -1
- package/lib/cjs/core/function/typed.js +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesBitXor.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesDotDivide.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesDotPow.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesEqual.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesLargerEq.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesLog.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSmallerEq.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesUnequal.generated.js +2 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesXor.generated.js +2 -0
- package/lib/cjs/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +1 -0
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +1 -0
- package/lib/cjs/entry/pureFunctionsAny.generated.js +11 -0
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/ceil.js +2 -2
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/fix.js +2 -2
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/floor.js +2 -2
- package/lib/cjs/expression/parse.js +26 -36
- package/lib/cjs/function/algebra/simplify.js +4 -3
- package/lib/cjs/function/algebra/simplifyConstant.js +5 -11
- package/lib/cjs/function/arithmetic/ceil.js +21 -2
- package/lib/cjs/function/arithmetic/dotDivide.js +4 -3
- package/lib/cjs/function/arithmetic/dotPow.js +4 -3
- package/lib/cjs/function/arithmetic/fix.js +24 -5
- package/lib/cjs/function/arithmetic/floor.js +21 -2
- package/lib/cjs/function/arithmetic/log.js +12 -4
- package/lib/cjs/function/arithmetic/pow.js +2 -2
- package/lib/cjs/function/arithmetic/round.js +3 -5
- package/lib/cjs/function/arithmetic/sign.js +1 -1
- package/lib/cjs/function/bitwise/bitXor.js +4 -3
- package/lib/cjs/function/logical/xor.js +4 -3
- package/lib/cjs/function/matrix/filter.js +7 -0
- package/lib/cjs/function/matrix/forEach.js +7 -0
- package/lib/cjs/function/relational/equal.js +4 -3
- package/lib/cjs/function/relational/larger.js +4 -3
- package/lib/cjs/function/relational/largerEq.js +4 -3
- package/lib/cjs/function/relational/smaller.js +4 -3
- package/lib/cjs/function/relational/smallerEq.js +4 -3
- package/lib/cjs/function/relational/unequal.js +4 -3
- package/lib/cjs/function/utils/isInteger.js +1 -1
- package/lib/cjs/function/utils/isNegative.js +1 -1
- package/lib/cjs/function/utils/isPositive.js +1 -1
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/type/bignumber/function/bignumber.js +2 -2
- package/lib/cjs/type/fraction/Fraction.js +4 -4
- package/lib/cjs/type/fraction/function/fraction.js +3 -0
- package/lib/cjs/type/matrix/utils/matAlgo07xSSf.js +39 -43
- package/lib/cjs/type/unit/Unit.js +1 -1
- package/lib/cjs/utils/object.js +4 -0
- package/lib/cjs/utils/string.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/function/import.js +4 -1
- package/lib/esm/core/function/typed.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesBitXor.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesDotDivide.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesDotPow.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesEqual.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesLarger.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesLargerEq.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesLog.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSmaller.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSmallerEq.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesUnequal.generated.js +2 -0
- package/lib/esm/entry/dependenciesAny/dependenciesXor.generated.js +2 -0
- package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +2 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +1 -0
- package/lib/esm/entry/impureFunctionsNumber.generated.js +1 -0
- package/lib/esm/entry/pureFunctionsAny.generated.js +11 -0
- package/lib/esm/expression/embeddedDocs/function/arithmetic/ceil.js +2 -2
- package/lib/esm/expression/embeddedDocs/function/arithmetic/fix.js +2 -2
- package/lib/esm/expression/embeddedDocs/function/arithmetic/floor.js +2 -2
- package/lib/esm/expression/parse.js +26 -36
- package/lib/esm/function/algebra/simplify.js +4 -3
- package/lib/esm/function/algebra/simplifyConstant.js +5 -11
- package/lib/esm/function/arithmetic/ceil.js +21 -2
- package/lib/esm/function/arithmetic/dotDivide.js +4 -3
- package/lib/esm/function/arithmetic/dotPow.js +4 -3
- package/lib/esm/function/arithmetic/fix.js +24 -5
- package/lib/esm/function/arithmetic/floor.js +21 -2
- package/lib/esm/function/arithmetic/log.js +12 -4
- package/lib/esm/function/arithmetic/pow.js +2 -2
- package/lib/esm/function/arithmetic/round.js +3 -5
- package/lib/esm/function/arithmetic/sign.js +1 -1
- package/lib/esm/function/bitwise/bitXor.js +4 -3
- package/lib/esm/function/logical/xor.js +4 -3
- package/lib/esm/function/matrix/filter.js +7 -0
- package/lib/esm/function/matrix/forEach.js +7 -0
- package/lib/esm/function/relational/equal.js +4 -3
- package/lib/esm/function/relational/larger.js +4 -3
- package/lib/esm/function/relational/largerEq.js +4 -3
- package/lib/esm/function/relational/smaller.js +4 -3
- package/lib/esm/function/relational/smallerEq.js +4 -3
- package/lib/esm/function/relational/unequal.js +4 -3
- package/lib/esm/function/utils/isInteger.js +1 -1
- package/lib/esm/function/utils/isNegative.js +1 -1
- package/lib/esm/function/utils/isPositive.js +1 -1
- package/lib/esm/type/bignumber/function/bignumber.js +2 -2
- package/lib/esm/type/fraction/Fraction.js +4 -4
- package/lib/esm/type/fraction/function/fraction.js +3 -0
- package/lib/esm/type/matrix/utils/matAlgo07xSSf.js +39 -43
- package/lib/esm/type/unit/Unit.js +1 -1
- package/lib/esm/utils/object.js +4 -0
- package/lib/esm/utils/string.js +2 -2
- package/lib/esm/version.js +1 -1
- package/package.json +3 -3
- package/types/index.d.ts +115 -25
@@ -932,7 +932,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
932
932
|
*/
|
933
933
|
function parseAddSubtract(state) {
|
934
934
|
var node, name, fn, params;
|
935
|
-
node =
|
935
|
+
node = parseMultiplyDivideModulusPercentage(state);
|
936
936
|
var operators = {
|
937
937
|
'+': 'add',
|
938
938
|
'-': 'subtract'
|
@@ -941,7 +941,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
941
941
|
name = state.token;
|
942
942
|
fn = operators[name];
|
943
943
|
getTokenSkipNewline(state);
|
944
|
-
var rightNode =
|
944
|
+
var rightNode = parseMultiplyDivideModulusPercentage(state);
|
945
945
|
if (rightNode.isPercentage) {
|
946
946
|
params = [node, new OperatorNode('*', 'multiply', [node, rightNode])];
|
947
947
|
} else {
|
@@ -953,11 +953,11 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
953
953
|
}
|
954
954
|
|
955
955
|
/**
|
956
|
-
* multiply, divide
|
956
|
+
* multiply, divide, modulus, percentage
|
957
957
|
* @return {Node} node
|
958
958
|
* @private
|
959
959
|
*/
|
960
|
-
function
|
960
|
+
function parseMultiplyDivideModulusPercentage(state) {
|
961
961
|
var node, last, name, fn;
|
962
962
|
node = parseImplicitMultiplication(state);
|
963
963
|
last = node;
|
@@ -965,7 +965,9 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
965
965
|
'*': 'multiply',
|
966
966
|
'.*': 'dotMultiply',
|
967
967
|
'/': 'divide',
|
968
|
-
'./': 'dotDivide'
|
968
|
+
'./': 'dotDivide',
|
969
|
+
'%': 'mod',
|
970
|
+
mod: 'mod'
|
969
971
|
};
|
970
972
|
while (true) {
|
971
973
|
if (hasOwnProperty(operators, state.token)) {
|
@@ -973,8 +975,23 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
973
975
|
name = state.token;
|
974
976
|
fn = operators[name];
|
975
977
|
getTokenSkipNewline(state);
|
976
|
-
|
977
|
-
|
978
|
+
if (name === '%' && state.tokenType === TOKENTYPE.DELIMITER && state.token !== '(') {
|
979
|
+
// If the expression contains only %, then treat that as /100
|
980
|
+
if (state.token !== '' && operators[state.token]) {
|
981
|
+
var left = new OperatorNode('/', 'divide', [node, new ConstantNode(100)], false, true);
|
982
|
+
name = state.token;
|
983
|
+
fn = operators[name];
|
984
|
+
getTokenSkipNewline(state);
|
985
|
+
last = parseImplicitMultiplication(state);
|
986
|
+
node = new OperatorNode(name, fn, [left, last]);
|
987
|
+
} else {
|
988
|
+
node = new OperatorNode('/', 'divide', [node, new ConstantNode(100)], false, true);
|
989
|
+
}
|
990
|
+
// return node
|
991
|
+
} else {
|
992
|
+
last = parseImplicitMultiplication(state);
|
993
|
+
node = new OperatorNode(name, fn, [node, last]);
|
994
|
+
}
|
978
995
|
} else {
|
979
996
|
break;
|
980
997
|
}
|
@@ -1017,7 +1034,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1017
1034
|
* @private
|
1018
1035
|
*/
|
1019
1036
|
function parseRule2(state) {
|
1020
|
-
var node =
|
1037
|
+
var node = parseUnary(state);
|
1021
1038
|
var last = node;
|
1022
1039
|
var tokenStates = [];
|
1023
1040
|
while (true) {
|
@@ -1039,7 +1056,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1039
1056
|
// Rewind once and build the "number / number" node; the symbol will be consumed later
|
1040
1057
|
_extends(state, tokenStates.pop());
|
1041
1058
|
tokenStates.pop();
|
1042
|
-
last =
|
1059
|
+
last = parseUnary(state);
|
1043
1060
|
node = new OperatorNode('/', 'divide', [node, last]);
|
1044
1061
|
} else {
|
1045
1062
|
// Not a match, so rewind
|
@@ -1059,33 +1076,6 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1059
1076
|
return node;
|
1060
1077
|
}
|
1061
1078
|
|
1062
|
-
/**
|
1063
|
-
* modulus and percentage
|
1064
|
-
* @return {Node} node
|
1065
|
-
* @private
|
1066
|
-
*/
|
1067
|
-
function parseModulusPercentage(state) {
|
1068
|
-
var node, name, fn, params;
|
1069
|
-
node = parseUnary(state);
|
1070
|
-
var operators = {
|
1071
|
-
'%': 'mod',
|
1072
|
-
mod: 'mod'
|
1073
|
-
};
|
1074
|
-
while (hasOwnProperty(operators, state.token)) {
|
1075
|
-
name = state.token;
|
1076
|
-
fn = operators[name];
|
1077
|
-
getTokenSkipNewline(state);
|
1078
|
-
if (name === '%' && state.tokenType === TOKENTYPE.DELIMITER && state.token !== '(') {
|
1079
|
-
// If the expression contains only %, then treat that as /100
|
1080
|
-
node = new OperatorNode('/', 'divide', [node, new ConstantNode(100)], false, true);
|
1081
|
-
} else {
|
1082
|
-
params = [node, parseUnary(state)];
|
1083
|
-
node = new OperatorNode(name, fn, params);
|
1084
|
-
}
|
1085
|
-
}
|
1086
|
-
return node;
|
1087
|
-
}
|
1088
|
-
|
1089
1079
|
/**
|
1090
1080
|
* Unary plus and minus, and logical and bitwise not
|
1091
1081
|
* @return {Node} node
|
@@ -5,7 +5,7 @@ import { createUtil } from './simplify/util.js';
|
|
5
5
|
import { hasOwnProperty } from '../../utils/object.js';
|
6
6
|
import { createEmptyMap, createMap } from '../../utils/map.js';
|
7
7
|
var name = 'simplify';
|
8
|
-
var dependencies = ['typed', 'parse', 'equal', 'resolve', 'simplifyConstant', 'simplifyCore', 'AccessorNode', 'ArrayNode', 'ConstantNode', 'FunctionNode', 'IndexNode', 'ObjectNode', 'OperatorNode', 'ParenthesisNode', 'SymbolNode'];
|
8
|
+
var dependencies = ['typed', 'parse', 'equal', 'resolve', 'simplifyConstant', 'simplifyCore', 'AccessorNode', 'ArrayNode', 'ConstantNode', 'FunctionNode', 'IndexNode', 'ObjectNode', 'OperatorNode', 'ParenthesisNode', 'SymbolNode', 'replacer'];
|
9
9
|
export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
10
10
|
var {
|
11
11
|
typed,
|
@@ -22,7 +22,8 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
22
22
|
ObjectNode,
|
23
23
|
OperatorNode,
|
24
24
|
ParenthesisNode,
|
25
|
-
SymbolNode
|
25
|
+
SymbolNode,
|
26
|
+
replacer
|
26
27
|
} = _ref;
|
27
28
|
var {
|
28
29
|
hasProperty,
|
@@ -998,7 +999,7 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
998
999
|
var uniqueSets = [];
|
999
1000
|
var unique = {};
|
1000
1001
|
for (var i = 0; i < sets.length; i++) {
|
1001
|
-
var s = JSON.stringify(sets[i]);
|
1002
|
+
var s = JSON.stringify(sets[i], replacer);
|
1002
1003
|
if (!unique[s]) {
|
1003
1004
|
unique[s] = true;
|
1004
1005
|
uniqueSets.push(sets[i]);
|
@@ -194,17 +194,11 @@ export var createSimplifyConstant = /* #__PURE__ */factory(name, dependencies, _
|
|
194
194
|
return new OperatorNode('-', 'unaryMinus', [n]);
|
195
195
|
}
|
196
196
|
function _fractionToNode(f) {
|
197
|
-
|
198
|
-
var
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
n = new ConstantNode(vn);
|
203
|
-
}
|
204
|
-
if (f.d === 1) {
|
205
|
-
return n;
|
206
|
-
}
|
207
|
-
return new OperatorNode('/', 'divide', [n, new ConstantNode(f.d)]);
|
197
|
+
// note: we convert await from bigint values, because bigint values gives issues with divisions: 1n/2n=0n and not 0.5
|
198
|
+
var fromBigInt = value => config.number === 'BigNumber' && bignumber ? bignumber(value) : Number(value);
|
199
|
+
var numeratorValue = f.s * f.n;
|
200
|
+
var numeratorNode = numeratorValue < 0n ? new OperatorNode('-', 'unaryMinus', [new ConstantNode(-fromBigInt(numeratorValue))]) : new ConstantNode(fromBigInt(numeratorValue));
|
201
|
+
return f.d === 1n ? numeratorNode : new OperatorNode('/', 'divide', [numeratorNode, new ConstantNode(fromBigInt(f.d))]);
|
208
202
|
}
|
209
203
|
|
210
204
|
/* Handles constant indexing of ArrayNodes, matrices, and ObjectNodes */
|
@@ -69,6 +69,8 @@ export var createCeil = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
69
69
|
*
|
70
70
|
* math.ceil(x)
|
71
71
|
* math.ceil(x, n)
|
72
|
+
* math.ceil(unit, valuelessUnit)
|
73
|
+
* math.ceil(unit, n, valuelessUnit)
|
72
74
|
*
|
73
75
|
* Examples:
|
74
76
|
*
|
@@ -86,6 +88,12 @@ export var createCeil = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
86
88
|
* math.ceil(c) // returns Complex 4 - 2i
|
87
89
|
* math.ceil(c, 1) // returns Complex 3.3 - 2.7i
|
88
90
|
*
|
91
|
+
* const unit = math.unit('3.241 cm')
|
92
|
+
* const cm = math.unit('cm')
|
93
|
+
* const mm = math.unit('mm')
|
94
|
+
* math.ceil(unit, 1, cm) // returns Unit 3.3 cm
|
95
|
+
* math.ceil(unit, 1, mm) // returns Unit 32.5 mm
|
96
|
+
*
|
89
97
|
* math.ceil([3.2, 3.8, -4.7]) // returns Array [4, 4, -4]
|
90
98
|
* math.ceil([3.21, 3.82, -4.71], 1) // returns Array [3.3, 3.9, -4.7]
|
91
99
|
*
|
@@ -93,9 +101,10 @@ export var createCeil = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
93
101
|
*
|
94
102
|
* floor, fix, round
|
95
103
|
*
|
96
|
-
* @param {number | BigNumber | Fraction | Complex | Array | Matrix} x
|
104
|
+
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Value to be rounded
|
97
105
|
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
98
|
-
* @
|
106
|
+
* @param {Unit} [valuelessUnit] A valueless unit
|
107
|
+
* @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Rounded value
|
99
108
|
*/
|
100
109
|
return typed('ceil', {
|
101
110
|
number: ceilNumber.signatures.number,
|
@@ -132,6 +141,16 @@ export var createCeil = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
132
141
|
'Fraction, BigNumber': function Fraction_BigNumber(x, n) {
|
133
142
|
return x.ceil(n.toNumber());
|
134
143
|
},
|
144
|
+
'Unit, number, Unit': typed.referToSelf(self => function (x, n, unit) {
|
145
|
+
var valueless = x.toNumeric(unit);
|
146
|
+
return unit.multiply(self(valueless, n));
|
147
|
+
}),
|
148
|
+
'Unit, BigNumber, Unit': typed.referToSelf(self => (x, n, unit) => self(x, n.toNumber(), unit)),
|
149
|
+
'Array | Matrix, number | BigNumber, Unit': typed.referToSelf(self => (x, n, unit) => {
|
150
|
+
// deep map collection, skip zeros since ceil(0) = 0
|
151
|
+
return deepMap(x, value => self(value, n, unit), true);
|
152
|
+
}),
|
153
|
+
'Array | Matrix | Unit, Unit': typed.referToSelf(self => (x, unit) => self(x, 0, unit)),
|
135
154
|
'Array | Matrix': typed.referToSelf(self => x => {
|
136
155
|
// deep map collection, skip zeros since ceil(0) = 0
|
137
156
|
return deepMap(x, self, true);
|
@@ -6,7 +6,7 @@ import { createMatAlgo11xS0s } from '../../type/matrix/utils/matAlgo11xS0s.js';
|
|
6
6
|
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
|
7
7
|
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
|
8
8
|
var name = 'dotDivide';
|
9
|
-
var dependencies = ['typed', 'matrix', 'equalScalar', 'divideScalar', 'DenseMatrix', 'concat'];
|
9
|
+
var dependencies = ['typed', 'matrix', 'equalScalar', 'divideScalar', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
10
10
|
export var createDotDivide = /* #__PURE__ */factory(name, dependencies, _ref => {
|
11
11
|
var {
|
12
12
|
typed,
|
@@ -14,7 +14,8 @@ export var createDotDivide = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
14
14
|
equalScalar,
|
15
15
|
divideScalar,
|
16
16
|
DenseMatrix,
|
17
|
-
concat
|
17
|
+
concat,
|
18
|
+
SparseMatrix
|
18
19
|
} = _ref;
|
19
20
|
var matAlgo02xDS0 = createMatAlgo02xDS0({
|
20
21
|
typed,
|
@@ -25,7 +26,7 @@ export var createDotDivide = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
25
26
|
});
|
26
27
|
var matAlgo07xSSf = createMatAlgo07xSSf({
|
27
28
|
typed,
|
28
|
-
|
29
|
+
SparseMatrix
|
29
30
|
});
|
30
31
|
var matAlgo11xS0s = createMatAlgo11xS0s({
|
31
32
|
typed,
|
@@ -5,7 +5,7 @@ import { createMatAlgo11xS0s } from '../../type/matrix/utils/matAlgo11xS0s.js';
|
|
5
5
|
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
|
6
6
|
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
|
7
7
|
var name = 'dotPow';
|
8
|
-
var dependencies = ['typed', 'equalScalar', 'matrix', 'pow', 'DenseMatrix', 'concat'];
|
8
|
+
var dependencies = ['typed', 'equalScalar', 'matrix', 'pow', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
9
9
|
export var createDotPow = /* #__PURE__ */factory(name, dependencies, _ref => {
|
10
10
|
var {
|
11
11
|
typed,
|
@@ -13,14 +13,15 @@ export var createDotPow = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
13
13
|
matrix,
|
14
14
|
pow,
|
15
15
|
DenseMatrix,
|
16
|
-
concat
|
16
|
+
concat,
|
17
|
+
SparseMatrix
|
17
18
|
} = _ref;
|
18
19
|
var matAlgo03xDSf = createMatAlgo03xDSf({
|
19
20
|
typed
|
20
21
|
});
|
21
22
|
var matAlgo07xSSf = createMatAlgo07xSSf({
|
22
23
|
typed,
|
23
|
-
|
24
|
+
SparseMatrix
|
24
25
|
});
|
25
26
|
var matAlgo11xS0s = createMatAlgo11xS0s({
|
26
27
|
typed,
|
@@ -50,6 +50,8 @@ export var createFix = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
50
50
|
*
|
51
51
|
* math.fix(x)
|
52
52
|
* math.fix(x,n)
|
53
|
+
* math.fix(unit, valuelessUnit)
|
54
|
+
* math.fix(unit, n, valuelessUnit)
|
53
55
|
*
|
54
56
|
* Examples:
|
55
57
|
*
|
@@ -67,6 +69,12 @@ export var createFix = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
67
69
|
* math.fix(c) // returns Complex 3 - 2i
|
68
70
|
* math.fix(c, 1) // returns Complex 3.2 -2.7i
|
69
71
|
*
|
72
|
+
* const unit = math.unit('3.241 cm')
|
73
|
+
* const cm = math.unit('cm')
|
74
|
+
* const mm = math.unit('mm')
|
75
|
+
* math.fix(unit, 1, cm) // returns Unit 3.2 cm
|
76
|
+
* math.fix(unit, 1, mm) // returns Unit 32.4 mm
|
77
|
+
*
|
70
78
|
* math.fix([3.2, 3.8, -4.7]) // returns Array [3, 3, -4]
|
71
79
|
* math.fix([3.2, 3.8, -4.7], 1) // returns Array [3.2, 3.8, -4.7]
|
72
80
|
*
|
@@ -74,9 +82,10 @@ export var createFix = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
74
82
|
*
|
75
83
|
* ceil, floor, round
|
76
84
|
*
|
77
|
-
* @param {number | BigNumber | Fraction | Complex | Array | Matrix} x
|
78
|
-
* @param {number | BigNumber | Array} [n=0]
|
79
|
-
* @
|
85
|
+
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Value to be rounded
|
86
|
+
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
87
|
+
* @param {Unit} [valuelessUnit] A valueless unit
|
88
|
+
* @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Rounded value
|
80
89
|
*/
|
81
90
|
return typed('fix', {
|
82
91
|
number: fixNumber.signatures.number,
|
@@ -98,11 +107,21 @@ export var createFix = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
98
107
|
return x.isNegative() ? ceil(x, n) : floor(x, n);
|
99
108
|
},
|
100
109
|
Fraction: function Fraction(x) {
|
101
|
-
return x.s <
|
110
|
+
return x.s < 0n ? x.ceil() : x.floor();
|
102
111
|
},
|
103
112
|
'Fraction, number | BigNumber': function Fraction_number__BigNumber(x, n) {
|
104
|
-
return x.s <
|
113
|
+
return x.s < 0n ? ceil(x, n) : floor(x, n);
|
105
114
|
},
|
115
|
+
'Unit, number, Unit': typed.referToSelf(self => function (x, n, unit) {
|
116
|
+
var valueless = x.toNumeric(unit);
|
117
|
+
return unit.multiply(self(valueless, n));
|
118
|
+
}),
|
119
|
+
'Unit, BigNumber, Unit': typed.referToSelf(self => (x, n, unit) => self(x, n.toNumber(), unit)),
|
120
|
+
'Array | Matrix, number | BigNumber, Unit': typed.referToSelf(self => (x, n, unit) => {
|
121
|
+
// deep map collection, skip zeros since fix(0) = 0
|
122
|
+
return deepMap(x, value => self(value, n, unit), true);
|
123
|
+
}),
|
124
|
+
'Array | Matrix | Unit, Unit': typed.referToSelf(self => (x, unit) => self(x, 0, unit)),
|
106
125
|
'Array | Matrix': typed.referToSelf(self => x => {
|
107
126
|
// deep map collection, skip zeros since fix(0) = 0
|
108
127
|
return deepMap(x, self, true);
|
@@ -68,6 +68,8 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
68
68
|
*
|
69
69
|
* math.floor(x)
|
70
70
|
* math.floor(x, n)
|
71
|
+
* math.floor(unit, valuelessUnit)
|
72
|
+
* math.floor(unit, n, valuelessUnit)
|
71
73
|
*
|
72
74
|
* Examples:
|
73
75
|
*
|
@@ -85,6 +87,12 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
85
87
|
* math.floor(c) // returns Complex 3 - 3i
|
86
88
|
* math.floor(c, 1) // returns Complex 3.2 -2.8i
|
87
89
|
*
|
90
|
+
* const unit = math.unit('3.241 cm')
|
91
|
+
* const cm = math.unit('cm')
|
92
|
+
* const mm = math.unit('mm')
|
93
|
+
* math.floor(unit, 1, cm) // returns Unit 3.2 cm
|
94
|
+
* math.floor(unit, 1, mm) // returns Unit 32.4 mm
|
95
|
+
*
|
88
96
|
* math.floor([3.2, 3.8, -4.7]) // returns Array [3, 3, -5]
|
89
97
|
* math.floor([3.21, 3.82, -4.71], 1) // returns Array [3.2, 3.8, -4.8]
|
90
98
|
*
|
@@ -96,9 +104,10 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
96
104
|
*
|
97
105
|
* ceil, fix, round
|
98
106
|
*
|
99
|
-
* @param {number | BigNumber | Fraction | Complex | Array | Matrix} x
|
107
|
+
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Value to be rounded
|
100
108
|
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
101
|
-
* @
|
109
|
+
* @param {Unit} [valuelessUnit] A valueless unit
|
110
|
+
* @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Rounded value
|
102
111
|
*/
|
103
112
|
return typed('floor', {
|
104
113
|
number: floorNumber.signatures.number,
|
@@ -135,6 +144,16 @@ export var createFloor = /* #__PURE__ */factory(name, dependencies, _ref2 => {
|
|
135
144
|
'Fraction, BigNumber': function Fraction_BigNumber(x, n) {
|
136
145
|
return x.floor(n.toNumber());
|
137
146
|
},
|
147
|
+
'Unit, number, Unit': typed.referToSelf(self => function (x, n, unit) {
|
148
|
+
var valueless = x.toNumeric(unit);
|
149
|
+
return unit.multiply(self(valueless, n));
|
150
|
+
}),
|
151
|
+
'Unit, BigNumber, Unit': typed.referToSelf(self => (x, n, unit) => self(x, n.toNumber(), unit)),
|
152
|
+
'Array | Matrix, number | BigNumber, Unit': typed.referToSelf(self => (x, n, unit) => {
|
153
|
+
// deep map collection, skip zeros since floor(0) = 0
|
154
|
+
return deepMap(x, value => self(value, n, unit), true);
|
155
|
+
}),
|
156
|
+
'Array | Matrix | Unit, Unit': typed.referToSelf(self => (x, unit) => self(x, 0, unit)),
|
138
157
|
'Array | Matrix': typed.referToSelf(self => x => {
|
139
158
|
// deep map collection, skip zeros since floor(0) = 0
|
140
159
|
return deepMap(x, self, true);
|
@@ -1,10 +1,11 @@
|
|
1
1
|
import { factory } from '../../utils/factory.js';
|
2
2
|
import { logNumber } from '../../plain/number/index.js';
|
3
3
|
var name = 'log';
|
4
|
-
var dependencies = ['config', 'typed', 'divideScalar', 'Complex'];
|
4
|
+
var dependencies = ['config', 'typed', 'typeOf', 'divideScalar', 'Complex'];
|
5
5
|
export var createLog = /* #__PURE__ */factory(name, dependencies, _ref => {
|
6
6
|
var {
|
7
7
|
typed,
|
8
|
+
typeOf,
|
8
9
|
config,
|
9
10
|
divideScalar,
|
10
11
|
Complex
|
@@ -36,12 +37,12 @@ export var createLog = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
36
37
|
*
|
37
38
|
* exp, log2, log10, log1p
|
38
39
|
*
|
39
|
-
* @param {number | BigNumber | Complex} x
|
40
|
+
* @param {number | BigNumber | Fraction | Complex} x
|
40
41
|
* Value for which to calculate the logarithm.
|
41
|
-
* @param {number | BigNumber | Complex} [base=e]
|
42
|
+
* @param {number | BigNumber | Fraction | Complex} [base=e]
|
42
43
|
* Optional base for the logarithm. If not provided, the natural
|
43
44
|
* logarithm of `x` is calculated.
|
44
|
-
* @return {number | BigNumber | Complex}
|
45
|
+
* @return {number | BigNumber | Fraction | Complex}
|
45
46
|
* Returns the logarithm of `x`
|
46
47
|
*/
|
47
48
|
return typed(name, {
|
@@ -66,6 +67,13 @@ export var createLog = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
66
67
|
},
|
67
68
|
'any, any': typed.referToSelf(self => (x, base) => {
|
68
69
|
// calculate logarithm for a specified base, log(x, base)
|
70
|
+
|
71
|
+
if (typeOf(x) === 'Fraction' && typeOf(base) === 'Fraction') {
|
72
|
+
var result = x.log(base);
|
73
|
+
if (result !== null) {
|
74
|
+
return result;
|
75
|
+
}
|
76
|
+
}
|
69
77
|
return divideScalar(self(x), self(base));
|
70
78
|
})
|
71
79
|
});
|
@@ -107,8 +107,8 @@ export var createPow = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
107
107
|
var yFrac = fraction(y);
|
108
108
|
var yNum = number(yFrac);
|
109
109
|
if (y === yNum || Math.abs((y - yNum) / y) < 1e-14) {
|
110
|
-
if (yFrac.d %
|
111
|
-
return (yFrac.n %
|
110
|
+
if (yFrac.d % 2n === 1n) {
|
111
|
+
return (yFrac.n % 2n === 0n ? 1 : -1) * Math.pow(-x, y);
|
112
112
|
}
|
113
113
|
}
|
114
114
|
} catch (ex) {
|
@@ -76,7 +76,7 @@ export var createRound = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
76
76
|
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Value to be rounded
|
77
77
|
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
78
78
|
* @param {Unit} [valuelessUnit] A valueless unit
|
79
|
-
* @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
|
79
|
+
* @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Rounded value
|
80
80
|
*/
|
81
81
|
return typed(name, {
|
82
82
|
number: function number(x) {
|
@@ -157,13 +157,11 @@ export var createRound = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
157
157
|
return unit.multiply(self(valueless, n));
|
158
158
|
}),
|
159
159
|
'Unit, BigNumber, Unit': typed.referToSelf(self => (x, n, unit) => self(x, n.toNumber(), unit)),
|
160
|
-
'
|
161
|
-
'Array | Matrix, number, Unit': typed.referToSelf(self => (x, n, unit) => {
|
160
|
+
'Array | Matrix, number | BigNumber, Unit': typed.referToSelf(self => (x, n, unit) => {
|
162
161
|
// deep map collection, skip zeros since round(0) = 0
|
163
162
|
return deepMap(x, value => self(value, n, unit), true);
|
164
163
|
}),
|
165
|
-
'Array | Matrix
|
166
|
-
'Array | Matrix, Unit': typed.referToSelf(self => (x, unit) => self(x, 0, unit)),
|
164
|
+
'Array | Matrix | Unit, Unit': typed.referToSelf(self => (x, unit) => self(x, 0, unit)),
|
167
165
|
'Array | Matrix': typed.referToSelf(self => x => {
|
168
166
|
// deep map collection, skip zeros since round(0) = 0
|
169
167
|
return deepMap(x, self, true);
|
@@ -52,7 +52,7 @@ export var createSign = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
52
52
|
return x > 0n ? 1n : x < 0n ? -1n : 0n;
|
53
53
|
},
|
54
54
|
Fraction: function Fraction(x) {
|
55
|
-
return new _Fraction(x.s
|
55
|
+
return new _Fraction(x.s);
|
56
56
|
},
|
57
57
|
// deep map collection, skip zeros since sign(0) = 0
|
58
58
|
'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self, true)),
|
@@ -6,20 +6,21 @@ import { factory } from '../../utils/factory.js';
|
|
6
6
|
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
|
7
7
|
import { bitXorNumber } from '../../plain/number/index.js';
|
8
8
|
var name = 'bitXor';
|
9
|
-
var dependencies = ['typed', 'matrix', 'DenseMatrix', 'concat'];
|
9
|
+
var dependencies = ['typed', 'matrix', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
10
10
|
export var createBitXor = /* #__PURE__ */factory(name, dependencies, _ref => {
|
11
11
|
var {
|
12
12
|
typed,
|
13
13
|
matrix,
|
14
14
|
DenseMatrix,
|
15
|
-
concat
|
15
|
+
concat,
|
16
|
+
SparseMatrix
|
16
17
|
} = _ref;
|
17
18
|
var matAlgo03xDSf = createMatAlgo03xDSf({
|
18
19
|
typed
|
19
20
|
});
|
20
21
|
var matAlgo07xSSf = createMatAlgo07xSSf({
|
21
22
|
typed,
|
22
|
-
|
23
|
+
SparseMatrix
|
23
24
|
});
|
24
25
|
var matAlgo12xSfs = createMatAlgo12xSfs({
|
25
26
|
typed,
|
@@ -5,20 +5,21 @@ import { factory } from '../../utils/factory.js';
|
|
5
5
|
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
|
6
6
|
import { xorNumber } from '../../plain/number/index.js';
|
7
7
|
var name = 'xor';
|
8
|
-
var dependencies = ['typed', 'matrix', 'DenseMatrix', 'concat'];
|
8
|
+
var dependencies = ['typed', 'matrix', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
9
9
|
export var createXor = /* #__PURE__ */factory(name, dependencies, _ref => {
|
10
10
|
var {
|
11
11
|
typed,
|
12
12
|
matrix,
|
13
13
|
DenseMatrix,
|
14
|
-
concat
|
14
|
+
concat,
|
15
|
+
SparseMatrix
|
15
16
|
} = _ref;
|
16
17
|
var matAlgo03xDSf = createMatAlgo03xDSf({
|
17
18
|
typed
|
18
19
|
});
|
19
20
|
var matAlgo07xSSf = createMatAlgo07xSSf({
|
20
21
|
typed,
|
21
|
-
|
22
|
+
SparseMatrix
|
22
23
|
});
|
23
24
|
var matAlgo12xSfs = createMatAlgo12xSfs({
|
24
25
|
typed,
|
@@ -10,6 +10,13 @@ export var createFilter = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
10
10
|
/**
|
11
11
|
* Filter the items in an array or one dimensional matrix.
|
12
12
|
*
|
13
|
+
* The callback is invoked with three arguments: the current value,
|
14
|
+
* the current index, and the matrix operated upon.
|
15
|
+
* Note that because the matrix/array might be
|
16
|
+
* multidimensional, the "index" argument is always an array of numbers giving
|
17
|
+
* the index in each dimension. This is true even for vectors: the "index"
|
18
|
+
* argument is an array of length 1, rather than simply a number.
|
19
|
+
*
|
13
20
|
* Syntax:
|
14
21
|
*
|
15
22
|
* math.filter(x, test)
|
@@ -10,6 +10,13 @@ export var createForEach = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
10
10
|
/**
|
11
11
|
* Iterate over all elements of a matrix/array, and executes the given callback function.
|
12
12
|
*
|
13
|
+
* The callback is invoked with three arguments: the current value,
|
14
|
+
* the current index, and the matrix operated upon.
|
15
|
+
* Note that because the matrix/array might be
|
16
|
+
* multidimensional, the "index" argument is always an array of numbers giving
|
17
|
+
* the index in each dimension. This is true even for vectors: the "index"
|
18
|
+
* argument is an array of length 1, rather than simply a number.
|
19
|
+
*
|
13
20
|
* Syntax:
|
14
21
|
*
|
15
22
|
* math.forEach(x, callback)
|
@@ -4,21 +4,22 @@ import { createMatAlgo07xSSf } from '../../type/matrix/utils/matAlgo07xSSf.js';
|
|
4
4
|
import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
|
5
5
|
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
|
6
6
|
var name = 'equal';
|
7
|
-
var dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix', 'concat'];
|
7
|
+
var dependencies = ['typed', 'matrix', 'equalScalar', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
8
8
|
export var createEqual = /* #__PURE__ */factory(name, dependencies, _ref => {
|
9
9
|
var {
|
10
10
|
typed,
|
11
11
|
matrix,
|
12
12
|
equalScalar,
|
13
13
|
DenseMatrix,
|
14
|
-
concat
|
14
|
+
concat,
|
15
|
+
SparseMatrix
|
15
16
|
} = _ref;
|
16
17
|
var matAlgo03xDSf = createMatAlgo03xDSf({
|
17
18
|
typed
|
18
19
|
});
|
19
20
|
var matAlgo07xSSf = createMatAlgo07xSSf({
|
20
21
|
typed,
|
21
|
-
|
22
|
+
SparseMatrix
|
22
23
|
});
|
23
24
|
var matAlgo12xSfs = createMatAlgo12xSfs({
|
24
25
|
typed,
|
@@ -7,21 +7,22 @@ import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
|
|
7
7
|
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
|
8
8
|
import { createCompareUnits } from './compareUnits.js';
|
9
9
|
var name = 'larger';
|
10
|
-
var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
|
10
|
+
var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
11
11
|
export var createLarger = /* #__PURE__ */factory(name, dependencies, _ref => {
|
12
12
|
var {
|
13
13
|
typed,
|
14
14
|
config,
|
15
15
|
matrix,
|
16
16
|
DenseMatrix,
|
17
|
-
concat
|
17
|
+
concat,
|
18
|
+
SparseMatrix
|
18
19
|
} = _ref;
|
19
20
|
var matAlgo03xDSf = createMatAlgo03xDSf({
|
20
21
|
typed
|
21
22
|
});
|
22
23
|
var matAlgo07xSSf = createMatAlgo07xSSf({
|
23
24
|
typed,
|
24
|
-
|
25
|
+
SparseMatrix
|
25
26
|
});
|
26
27
|
var matAlgo12xSfs = createMatAlgo12xSfs({
|
27
28
|
typed,
|
@@ -7,21 +7,22 @@ import { createMatAlgo12xSfs } from '../../type/matrix/utils/matAlgo12xSfs.js';
|
|
7
7
|
import { createMatrixAlgorithmSuite } from '../../type/matrix/utils/matrixAlgorithmSuite.js';
|
8
8
|
import { createCompareUnits } from './compareUnits.js';
|
9
9
|
var name = 'largerEq';
|
10
|
-
var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat'];
|
10
|
+
var dependencies = ['typed', 'config', 'matrix', 'DenseMatrix', 'concat', 'SparseMatrix'];
|
11
11
|
export var createLargerEq = /* #__PURE__ */factory(name, dependencies, _ref => {
|
12
12
|
var {
|
13
13
|
typed,
|
14
14
|
config,
|
15
15
|
matrix,
|
16
16
|
DenseMatrix,
|
17
|
-
concat
|
17
|
+
concat,
|
18
|
+
SparseMatrix
|
18
19
|
} = _ref;
|
19
20
|
var matAlgo03xDSf = createMatAlgo03xDSf({
|
20
21
|
typed
|
21
22
|
});
|
22
23
|
var matAlgo07xSSf = createMatAlgo07xSSf({
|
23
24
|
typed,
|
24
|
-
|
25
|
+
SparseMatrix
|
25
26
|
});
|
26
27
|
var matAlgo12xSfs = createMatAlgo12xSfs({
|
27
28
|
typed,
|