mathjs 9.4.5 → 9.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +9 -0
- package/docs/expressions/syntax.md +46 -43
- package/docs/reference/functions/setCartesian.md +3 -1
- package/lib/browser/math.js +3 -3
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesParserClass.generated.js +2 -2
- package/lib/cjs/entry/dependenciesNumber/dependenciesParserClass.generated.js +2 -2
- package/lib/cjs/entry/impureFunctionsAny.generated.js +1 -1
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +1 -1
- package/lib/cjs/expression/Parser.js +5 -4
- package/lib/cjs/expression/embeddedDocs/function/set/setCartesian.js +1 -1
- package/lib/cjs/expression/node/OperatorNode.js +9 -6
- package/lib/cjs/expression/parse.js +42 -6
- package/lib/cjs/function/set/setCartesian.js +3 -1
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesParserClass.generated.js +2 -2
- package/lib/esm/entry/dependenciesNumber/dependenciesParserClass.generated.js +2 -2
- package/lib/esm/entry/impureFunctionsAny.generated.js +1 -1
- package/lib/esm/entry/impureFunctionsNumber.generated.js +1 -1
- package/lib/esm/expression/Parser.js +5 -4
- package/lib/esm/expression/embeddedDocs/function/set/setCartesian.js +1 -1
- package/lib/esm/expression/node/OperatorNode.js +9 -6
- package/lib/esm/expression/parse.js +42 -6
- package/lib/esm/function/set/setCartesian.js +3 -1
- package/lib/esm/version.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +8 -8
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.ParserDependencies = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _dependenciesEvaluateGenerated = require("./dependenciesEvaluate.generated.js");
|
9
9
|
|
10
10
|
var _factoriesAny = require("../../factoriesAny.js");
|
11
11
|
|
@@ -14,7 +14,7 @@ var _factoriesAny = require("../../factoriesAny.js");
|
|
14
14
|
* DON'T MAKE CHANGES HERE
|
15
15
|
*/
|
16
16
|
var ParserDependencies = {
|
17
|
-
|
17
|
+
evaluateDependencies: _dependenciesEvaluateGenerated.evaluateDependencies,
|
18
18
|
createParserClass: _factoriesAny.createParserClass
|
19
19
|
};
|
20
20
|
exports.ParserDependencies = ParserDependencies;
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.ParserDependencies = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _dependenciesEvaluateGenerated = require("./dependenciesEvaluate.generated.js");
|
9
9
|
|
10
10
|
var _factoriesNumber = require("../../factoriesNumber.js");
|
11
11
|
|
@@ -14,7 +14,7 @@ var _factoriesNumber = require("../../factoriesNumber.js");
|
|
14
14
|
* DON'T MAKE CHANGES HERE
|
15
15
|
*/
|
16
16
|
var ParserDependencies = {
|
17
|
-
|
17
|
+
evaluateDependencies: _dependenciesEvaluateGenerated.evaluateDependencies,
|
18
18
|
createParserClass: _factoriesNumber.createParserClass
|
19
19
|
};
|
20
20
|
exports.ParserDependencies = ParserDependencies;
|
@@ -195,7 +195,7 @@ var rationalize = (0, _factoriesAny.createRationalize)({
|
|
195
195
|
});
|
196
196
|
exports.rationalize = rationalize;
|
197
197
|
var Parser = (0, _factoriesAny.createParserClass)({
|
198
|
-
|
198
|
+
evaluate: evaluate
|
199
199
|
});
|
200
200
|
exports.Parser = Parser;
|
201
201
|
var help = (0, _factoriesAny.createHelp)({
|
@@ -201,7 +201,7 @@ var help = (0, _factoriesNumber.createHelp)({
|
|
201
201
|
});
|
202
202
|
exports.help = help;
|
203
203
|
var Parser = (0, _factoriesNumber.createParserClass)({
|
204
|
-
|
204
|
+
evaluate: evaluate
|
205
205
|
});
|
206
206
|
exports.Parser = Parser;
|
207
207
|
var derivative = (0, _factoriesNumber.createDerivative)({
|
@@ -10,9 +10,9 @@ var _factory = require("../utils/factory.js");
|
|
10
10
|
var _map = require("../utils/map.js");
|
11
11
|
|
12
12
|
var name = 'Parser';
|
13
|
-
var dependencies = ['
|
13
|
+
var dependencies = ['evaluate'];
|
14
14
|
var createParserClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
15
|
-
var
|
15
|
+
var evaluate = _ref.evaluate;
|
16
16
|
|
17
17
|
/**
|
18
18
|
* @constructor Parser
|
@@ -81,14 +81,15 @@ var createParserClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
|
|
81
81
|
Parser.prototype.isParser = true;
|
82
82
|
/**
|
83
83
|
* Parse and evaluate the given expression
|
84
|
-
* @param {string} expr A string containing an expression,
|
84
|
+
* @param {string | string[]} expr A string containing an expression,
|
85
|
+
* for example "2+3", or a list with expressions
|
85
86
|
* @return {*} result The result, or undefined when the expression was empty
|
86
87
|
* @throws {Error}
|
87
88
|
*/
|
88
89
|
|
89
90
|
Parser.prototype.evaluate = function (expr) {
|
90
91
|
// TODO: validate arguments
|
91
|
-
return
|
92
|
+
return evaluate(expr, this.scope);
|
92
93
|
};
|
93
94
|
/**
|
94
95
|
* Get a variable (a function or variable) by name from the parsers scope.
|
@@ -8,7 +8,7 @@ var setCartesianDocs = {
|
|
8
8
|
name: 'setCartesian',
|
9
9
|
category: 'Set',
|
10
10
|
syntax: ['setCartesian(set1, set2)'],
|
11
|
-
description: 'Create the cartesian product of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.',
|
11
|
+
description: 'Create the cartesian product of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays and the values will be sorted in ascending order before the operation.',
|
12
12
|
examples: ['setCartesian([1, 2], [3, 4])'],
|
13
13
|
seealso: ['setUnion', 'setIntersect', 'setDifference', 'setPowerset']
|
14
14
|
};
|
@@ -33,8 +33,9 @@ var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
33
33
|
* @param {string} fn Function name, for example 'add'
|
34
34
|
* @param {Node[]} args Operator arguments
|
35
35
|
* @param {boolean} [implicit] Is this an implicit multiplication?
|
36
|
+
* @param {boolean} [isPercentage] Is this an percentage Operation?
|
36
37
|
*/
|
37
|
-
function OperatorNode(op, fn, args, implicit) {
|
38
|
+
function OperatorNode(op, fn, args, implicit, isPercentage) {
|
38
39
|
if (!(this instanceof OperatorNode)) {
|
39
40
|
throw new SyntaxError('Constructor must be called with the new operator');
|
40
41
|
} // validate input
|
@@ -53,6 +54,7 @@ var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
53
54
|
}
|
54
55
|
|
55
56
|
this.implicit = implicit === true;
|
57
|
+
this.isPercentage = isPercentage === true;
|
56
58
|
this.op = op;
|
57
59
|
this.fn = fn;
|
58
60
|
this.args = args || [];
|
@@ -135,7 +137,7 @@ var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
135
137
|
args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
|
136
138
|
}
|
137
139
|
|
138
|
-
return new OperatorNode(this.op, this.fn, args, this.implicit);
|
140
|
+
return new OperatorNode(this.op, this.fn, args, this.implicit, this.isPercentage);
|
139
141
|
};
|
140
142
|
/**
|
141
143
|
* Create a clone of this node, a shallow copy
|
@@ -144,7 +146,7 @@ var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
144
146
|
|
145
147
|
|
146
148
|
OperatorNode.prototype.clone = function () {
|
147
|
-
return new OperatorNode(this.op, this.fn, this.args.slice(0), this.implicit);
|
149
|
+
return new OperatorNode(this.op, this.fn, this.args.slice(0), this.implicit, this.isPercentage);
|
148
150
|
};
|
149
151
|
/**
|
150
152
|
* Check whether this is an unary OperatorNode:
|
@@ -478,20 +480,21 @@ var createOperatorNode = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
478
480
|
op: this.op,
|
479
481
|
fn: this.fn,
|
480
482
|
args: this.args,
|
481
|
-
implicit: this.implicit
|
483
|
+
implicit: this.implicit,
|
484
|
+
isPercentage: this.isPercentage
|
482
485
|
};
|
483
486
|
};
|
484
487
|
/**
|
485
488
|
* Instantiate an OperatorNode from its JSON representation
|
486
489
|
* @param {Object} json An object structured like
|
487
|
-
* `{"mathjs": "OperatorNode", "op": "+", "fn": "add", "args": [...], "implicit": false}`,
|
490
|
+
* `{"mathjs": "OperatorNode", "op": "+", "fn": "add", "args": [...], "implicit": false, "isPercentage":false}`,
|
488
491
|
* where mathjs is optional
|
489
492
|
* @returns {OperatorNode}
|
490
493
|
*/
|
491
494
|
|
492
495
|
|
493
496
|
OperatorNode.fromJSON = function (json) {
|
494
|
-
return new OperatorNode(json.op, json.fn, json.args, json.implicit);
|
497
|
+
return new OperatorNode(json.op, json.fn, json.args, json.implicit, json.isPercentage);
|
495
498
|
};
|
496
499
|
/**
|
497
500
|
* Get HTML representation.
|
@@ -1018,7 +1018,14 @@ var createParse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
1018
1018
|
name = state.token;
|
1019
1019
|
fn = operators[name];
|
1020
1020
|
getTokenSkipNewline(state);
|
1021
|
-
|
1021
|
+
var rightNode = parseMultiplyDivide(state);
|
1022
|
+
|
1023
|
+
if (rightNode.isPercentage) {
|
1024
|
+
params = [node, new OperatorNode('*', 'multiply', [node, rightNode])];
|
1025
|
+
} else {
|
1026
|
+
params = [node, rightNode];
|
1027
|
+
}
|
1028
|
+
|
1022
1029
|
node = new OperatorNode(name, fn, params);
|
1023
1030
|
}
|
1024
1031
|
|
@@ -1039,9 +1046,7 @@ var createParse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
1039
1046
|
'*': 'multiply',
|
1040
1047
|
'.*': 'dotMultiply',
|
1041
1048
|
'/': 'divide',
|
1042
|
-
'./': 'dotDivide'
|
1043
|
-
'%': 'mod',
|
1044
|
-
mod: 'mod'
|
1049
|
+
'./': 'dotDivide'
|
1045
1050
|
};
|
1046
1051
|
|
1047
1052
|
while (true) {
|
@@ -1099,7 +1104,7 @@ var createParse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
1099
1104
|
|
1100
1105
|
|
1101
1106
|
function parseRule2(state) {
|
1102
|
-
var node =
|
1107
|
+
var node = parsePercentage(state);
|
1103
1108
|
var last = node;
|
1104
1109
|
var tokenStates = [];
|
1105
1110
|
|
@@ -1120,7 +1125,7 @@ var createParse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
1120
1125
|
// Rewind once and build the "number / number" node; the symbol will be consumed later
|
1121
1126
|
(0, _extends2["default"])(state, tokenStates.pop());
|
1122
1127
|
tokenStates.pop();
|
1123
|
-
last =
|
1128
|
+
last = parsePercentage(state);
|
1124
1129
|
node = new OperatorNode('/', 'divide', [node, last]);
|
1125
1130
|
} else {
|
1126
1131
|
// Not a match, so rewind
|
@@ -1140,6 +1145,37 @@ var createParse = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
|
|
1140
1145
|
|
1141
1146
|
return node;
|
1142
1147
|
}
|
1148
|
+
/**
|
1149
|
+
* percentage or mod
|
1150
|
+
* @return {Node} node
|
1151
|
+
* @private
|
1152
|
+
*/
|
1153
|
+
|
1154
|
+
|
1155
|
+
function parsePercentage(state) {
|
1156
|
+
var node, name, fn, params;
|
1157
|
+
node = parseUnary(state);
|
1158
|
+
var operators = {
|
1159
|
+
'%': 'mod',
|
1160
|
+
mod: 'mod'
|
1161
|
+
};
|
1162
|
+
|
1163
|
+
while ((0, _object.hasOwnProperty)(operators, state.token)) {
|
1164
|
+
name = state.token;
|
1165
|
+
fn = operators[name];
|
1166
|
+
getTokenSkipNewline(state);
|
1167
|
+
|
1168
|
+
if (name === '%' && state.tokenType === TOKENTYPE.DELIMITER && state.token !== '(') {
|
1169
|
+
// If the expression contains only %, then treat that as /100
|
1170
|
+
node = new OperatorNode('/', 'divide', [node, new ConstantNode(100)], false, true);
|
1171
|
+
} else {
|
1172
|
+
params = [node, parseUnary(state)];
|
1173
|
+
node = new OperatorNode(name, fn, params);
|
1174
|
+
}
|
1175
|
+
}
|
1176
|
+
|
1177
|
+
return node;
|
1178
|
+
}
|
1143
1179
|
/**
|
1144
1180
|
* Unary plus and minus, and logical and bitwise not
|
1145
1181
|
* @return {Node} node
|
@@ -21,7 +21,8 @@ var createSetCartesian = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
21
21
|
|
22
22
|
/**
|
23
23
|
* Create the cartesian product of two (multi)sets.
|
24
|
-
* Multi-dimension arrays will be converted to single-dimension arrays
|
24
|
+
* Multi-dimension arrays will be converted to single-dimension arrays
|
25
|
+
* and the values will be sorted in ascending order before the operation.
|
25
26
|
*
|
26
27
|
* Syntax:
|
27
28
|
*
|
@@ -30,6 +31,7 @@ var createSetCartesian = /* #__PURE__ */(0, _factory.factory)(name, dependencies
|
|
30
31
|
* Examples:
|
31
32
|
*
|
32
33
|
* math.setCartesian([1, 2], [3, 4]) // returns [[1, 3], [1, 4], [2, 3], [2, 4]]
|
34
|
+
* math.setCartesian([4, 3], [2, 1]) // returns [[3, 1], [3, 2], [4, 1], [4, 2]]
|
33
35
|
*
|
34
36
|
* See also:
|
35
37
|
*
|
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 9.
|
10
|
-
* @date 2021-09-
|
9
|
+
* @version 9.5.0
|
10
|
+
* @date 2021-09-22
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2021 Jos de Jong <wjosdejong@gmail.com>
|
package/lib/cjs/version.js
CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.version = void 0;
|
7
|
-
var version = '9.
|
7
|
+
var version = '9.5.0'; // Note: This file is automatically generated when building math.js.
|
8
8
|
// Changes made in this file will be overwritten.
|
9
9
|
|
10
10
|
exports.version = version;
|
@@ -2,9 +2,9 @@
|
|
2
2
|
* THIS FILE IS AUTO-GENERATED
|
3
3
|
* DON'T MAKE CHANGES HERE
|
4
4
|
*/
|
5
|
-
import {
|
5
|
+
import { evaluateDependencies } from './dependenciesEvaluate.generated.js';
|
6
6
|
import { createParserClass } from '../../factoriesAny.js';
|
7
7
|
export var ParserDependencies = {
|
8
|
-
|
8
|
+
evaluateDependencies,
|
9
9
|
createParserClass
|
10
10
|
};
|
@@ -2,9 +2,9 @@
|
|
2
2
|
* THIS FILE IS AUTO-GENERATED
|
3
3
|
* DON'T MAKE CHANGES HERE
|
4
4
|
*/
|
5
|
-
import {
|
5
|
+
import { evaluateDependencies } from './dependenciesEvaluate.generated.js';
|
6
6
|
import { createParserClass } from '../../factoriesNumber.js';
|
7
7
|
export var ParserDependencies = {
|
8
|
-
|
8
|
+
evaluateDependencies,
|
9
9
|
createParserClass
|
10
10
|
};
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { factory } from '../utils/factory.js';
|
2
2
|
import { createEmptyMap, toObject } from '../utils/map.js';
|
3
3
|
var name = 'Parser';
|
4
|
-
var dependencies = ['
|
4
|
+
var dependencies = ['evaluate'];
|
5
5
|
export var createParserClass = /* #__PURE__ */factory(name, dependencies, _ref => {
|
6
6
|
var {
|
7
|
-
|
7
|
+
evaluate
|
8
8
|
} = _ref;
|
9
9
|
|
10
10
|
/**
|
@@ -74,14 +74,15 @@ export var createParserClass = /* #__PURE__ */factory(name, dependencies, _ref =
|
|
74
74
|
Parser.prototype.isParser = true;
|
75
75
|
/**
|
76
76
|
* Parse and evaluate the given expression
|
77
|
-
* @param {string} expr A string containing an expression,
|
77
|
+
* @param {string | string[]} expr A string containing an expression,
|
78
|
+
* for example "2+3", or a list with expressions
|
78
79
|
* @return {*} result The result, or undefined when the expression was empty
|
79
80
|
* @throws {Error}
|
80
81
|
*/
|
81
82
|
|
82
83
|
Parser.prototype.evaluate = function (expr) {
|
83
84
|
// TODO: validate arguments
|
84
|
-
return
|
85
|
+
return evaluate(expr, this.scope);
|
85
86
|
};
|
86
87
|
/**
|
87
88
|
* Get a variable (a function or variable) by name from the parsers scope.
|
@@ -2,7 +2,7 @@ export var setCartesianDocs = {
|
|
2
2
|
name: 'setCartesian',
|
3
3
|
category: 'Set',
|
4
4
|
syntax: ['setCartesian(set1, set2)'],
|
5
|
-
description: 'Create the cartesian product of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.',
|
5
|
+
description: 'Create the cartesian product of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays and the values will be sorted in ascending order before the operation.',
|
6
6
|
examples: ['setCartesian([1, 2], [3, 4])'],
|
7
7
|
seealso: ['setUnion', 'setIntersect', 'setDifference', 'setPowerset']
|
8
8
|
};
|
@@ -21,8 +21,9 @@ export var createOperatorNode = /* #__PURE__ */factory(name, dependencies, _ref
|
|
21
21
|
* @param {string} fn Function name, for example 'add'
|
22
22
|
* @param {Node[]} args Operator arguments
|
23
23
|
* @param {boolean} [implicit] Is this an implicit multiplication?
|
24
|
+
* @param {boolean} [isPercentage] Is this an percentage Operation?
|
24
25
|
*/
|
25
|
-
function OperatorNode(op, fn, args, implicit) {
|
26
|
+
function OperatorNode(op, fn, args, implicit, isPercentage) {
|
26
27
|
if (!(this instanceof OperatorNode)) {
|
27
28
|
throw new SyntaxError('Constructor must be called with the new operator');
|
28
29
|
} // validate input
|
@@ -41,6 +42,7 @@ export var createOperatorNode = /* #__PURE__ */factory(name, dependencies, _ref
|
|
41
42
|
}
|
42
43
|
|
43
44
|
this.implicit = implicit === true;
|
45
|
+
this.isPercentage = isPercentage === true;
|
44
46
|
this.op = op;
|
45
47
|
this.fn = fn;
|
46
48
|
this.args = args || [];
|
@@ -123,7 +125,7 @@ export var createOperatorNode = /* #__PURE__ */factory(name, dependencies, _ref
|
|
123
125
|
args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
|
124
126
|
}
|
125
127
|
|
126
|
-
return new OperatorNode(this.op, this.fn, args, this.implicit);
|
128
|
+
return new OperatorNode(this.op, this.fn, args, this.implicit, this.isPercentage);
|
127
129
|
};
|
128
130
|
/**
|
129
131
|
* Create a clone of this node, a shallow copy
|
@@ -132,7 +134,7 @@ export var createOperatorNode = /* #__PURE__ */factory(name, dependencies, _ref
|
|
132
134
|
|
133
135
|
|
134
136
|
OperatorNode.prototype.clone = function () {
|
135
|
-
return new OperatorNode(this.op, this.fn, this.args.slice(0), this.implicit);
|
137
|
+
return new OperatorNode(this.op, this.fn, this.args.slice(0), this.implicit, this.isPercentage);
|
136
138
|
};
|
137
139
|
/**
|
138
140
|
* Check whether this is an unary OperatorNode:
|
@@ -466,20 +468,21 @@ export var createOperatorNode = /* #__PURE__ */factory(name, dependencies, _ref
|
|
466
468
|
op: this.op,
|
467
469
|
fn: this.fn,
|
468
470
|
args: this.args,
|
469
|
-
implicit: this.implicit
|
471
|
+
implicit: this.implicit,
|
472
|
+
isPercentage: this.isPercentage
|
470
473
|
};
|
471
474
|
};
|
472
475
|
/**
|
473
476
|
* Instantiate an OperatorNode from its JSON representation
|
474
477
|
* @param {Object} json An object structured like
|
475
|
-
* `{"mathjs": "OperatorNode", "op": "+", "fn": "add", "args": [...], "implicit": false}`,
|
478
|
+
* `{"mathjs": "OperatorNode", "op": "+", "fn": "add", "args": [...], "implicit": false, "isPercentage":false}`,
|
476
479
|
* where mathjs is optional
|
477
480
|
* @returns {OperatorNode}
|
478
481
|
*/
|
479
482
|
|
480
483
|
|
481
484
|
OperatorNode.fromJSON = function (json) {
|
482
|
-
return new OperatorNode(json.op, json.fn, json.args, json.implicit);
|
485
|
+
return new OperatorNode(json.op, json.fn, json.args, json.implicit, json.isPercentage);
|
483
486
|
};
|
484
487
|
/**
|
485
488
|
* Get HTML representation.
|
@@ -1006,7 +1006,14 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1006
1006
|
name = state.token;
|
1007
1007
|
fn = operators[name];
|
1008
1008
|
getTokenSkipNewline(state);
|
1009
|
-
|
1009
|
+
var rightNode = parseMultiplyDivide(state);
|
1010
|
+
|
1011
|
+
if (rightNode.isPercentage) {
|
1012
|
+
params = [node, new OperatorNode('*', 'multiply', [node, rightNode])];
|
1013
|
+
} else {
|
1014
|
+
params = [node, rightNode];
|
1015
|
+
}
|
1016
|
+
|
1010
1017
|
node = new OperatorNode(name, fn, params);
|
1011
1018
|
}
|
1012
1019
|
|
@@ -1027,9 +1034,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1027
1034
|
'*': 'multiply',
|
1028
1035
|
'.*': 'dotMultiply',
|
1029
1036
|
'/': 'divide',
|
1030
|
-
'./': 'dotDivide'
|
1031
|
-
'%': 'mod',
|
1032
|
-
mod: 'mod'
|
1037
|
+
'./': 'dotDivide'
|
1033
1038
|
};
|
1034
1039
|
|
1035
1040
|
while (true) {
|
@@ -1087,7 +1092,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1087
1092
|
|
1088
1093
|
|
1089
1094
|
function parseRule2(state) {
|
1090
|
-
var node =
|
1095
|
+
var node = parsePercentage(state);
|
1091
1096
|
var last = node;
|
1092
1097
|
var tokenStates = [];
|
1093
1098
|
|
@@ -1109,7 +1114,7 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1109
1114
|
_extends(state, tokenStates.pop());
|
1110
1115
|
|
1111
1116
|
tokenStates.pop();
|
1112
|
-
last =
|
1117
|
+
last = parsePercentage(state);
|
1113
1118
|
node = new OperatorNode('/', 'divide', [node, last]);
|
1114
1119
|
} else {
|
1115
1120
|
// Not a match, so rewind
|
@@ -1132,6 +1137,37 @@ export var createParse = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1132
1137
|
|
1133
1138
|
return node;
|
1134
1139
|
}
|
1140
|
+
/**
|
1141
|
+
* percentage or mod
|
1142
|
+
* @return {Node} node
|
1143
|
+
* @private
|
1144
|
+
*/
|
1145
|
+
|
1146
|
+
|
1147
|
+
function parsePercentage(state) {
|
1148
|
+
var node, name, fn, params;
|
1149
|
+
node = parseUnary(state);
|
1150
|
+
var operators = {
|
1151
|
+
'%': 'mod',
|
1152
|
+
mod: 'mod'
|
1153
|
+
};
|
1154
|
+
|
1155
|
+
while (hasOwnProperty(operators, state.token)) {
|
1156
|
+
name = state.token;
|
1157
|
+
fn = operators[name];
|
1158
|
+
getTokenSkipNewline(state);
|
1159
|
+
|
1160
|
+
if (name === '%' && state.tokenType === TOKENTYPE.DELIMITER && state.token !== '(') {
|
1161
|
+
// If the expression contains only %, then treat that as /100
|
1162
|
+
node = new OperatorNode('/', 'divide', [node, new ConstantNode(100)], false, true);
|
1163
|
+
} else {
|
1164
|
+
params = [node, parseUnary(state)];
|
1165
|
+
node = new OperatorNode(name, fn, params);
|
1166
|
+
}
|
1167
|
+
}
|
1168
|
+
|
1169
|
+
return node;
|
1170
|
+
}
|
1135
1171
|
/**
|
1136
1172
|
* Unary plus and minus, and logical and bitwise not
|
1137
1173
|
* @return {Node} node
|
@@ -14,7 +14,8 @@ export var createSetCartesian = /* #__PURE__ */factory(name, dependencies, _ref
|
|
14
14
|
|
15
15
|
/**
|
16
16
|
* Create the cartesian product of two (multi)sets.
|
17
|
-
* Multi-dimension arrays will be converted to single-dimension arrays
|
17
|
+
* Multi-dimension arrays will be converted to single-dimension arrays
|
18
|
+
* and the values will be sorted in ascending order before the operation.
|
18
19
|
*
|
19
20
|
* Syntax:
|
20
21
|
*
|
@@ -23,6 +24,7 @@ export var createSetCartesian = /* #__PURE__ */factory(name, dependencies, _ref
|
|
23
24
|
* Examples:
|
24
25
|
*
|
25
26
|
* math.setCartesian([1, 2], [3, 4]) // returns [[1, 3], [1, 4], [2, 3], [2, 4]]
|
27
|
+
* math.setCartesian([4, 3], [2, 1]) // returns [[3, 1], [3, 2], [4, 1], [4, 2]]
|
26
28
|
*
|
27
29
|
* See also:
|
28
30
|
*
|
package/lib/esm/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export var version = '9.
|
1
|
+
export var version = '9.5.0'; // Note: This file is automatically generated when building math.js.
|
2
2
|
// Changes made in this file will be overwritten.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mathjs",
|
3
|
-
"version": "9.
|
3
|
+
"version": "9.5.0",
|
4
4
|
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
|
5
5
|
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
|
6
6
|
"homepage": "https://mathjs.org",
|
package/types/index.d.ts
CHANGED
@@ -21,7 +21,7 @@ declare namespace math {
|
|
21
21
|
interface FactoryFunctionMap {
|
22
22
|
[key: string]: FactoryFunction<any> | FactoryFunctionMap;
|
23
23
|
}
|
24
|
-
|
24
|
+
|
25
25
|
|
26
26
|
/** Available options for parse */
|
27
27
|
interface ParseOptions {
|
@@ -1808,8 +1808,8 @@ declare namespace math {
|
|
1808
1808
|
|
1809
1809
|
/**
|
1810
1810
|
* Create the cartesian product of two (multi)sets. Multi-dimension
|
1811
|
-
* arrays will be converted to single-dimension arrays
|
1812
|
-
* operation.
|
1811
|
+
* arrays will be converted to single-dimension arrays and the values
|
1812
|
+
* will be sorted in ascending order before the operation.
|
1813
1813
|
* @param a1 A (multi)set
|
1814
1814
|
* @param a2 A (multi)set
|
1815
1815
|
* @returns The cartesian product of two (multi)sets
|
@@ -2431,7 +2431,7 @@ declare namespace math {
|
|
2431
2431
|
|
2432
2432
|
/**
|
2433
2433
|
* Test whether a value is an numeric value. In case of a string,
|
2434
|
-
* true is returned if the string contains a numeric value.
|
2434
|
+
* true is returned if the string contains a numeric value.
|
2435
2435
|
* @param x Value to be tested
|
2436
2436
|
* @returns Returns true when x is a number, BigNumber, Fraction, Boolean, or a String containing number.
|
2437
2437
|
* Returns false for other types.
|
@@ -2948,7 +2948,7 @@ declare namespace math {
|
|
2948
2948
|
toJSON(): MathJSON;
|
2949
2949
|
formatUnits(): string;
|
2950
2950
|
format(options: FormatOptions): string;
|
2951
|
-
splitUnit(parts: ReadonlyArray<string | Unit>): Unit[];
|
2951
|
+
splitUnit(parts: ReadonlyArray<string | Unit>): Unit[];
|
2952
2952
|
}
|
2953
2953
|
|
2954
2954
|
interface CreateUnitOptions {
|
@@ -3155,7 +3155,7 @@ declare namespace math {
|
|
3155
3155
|
}
|
3156
3156
|
|
3157
3157
|
interface Parser {
|
3158
|
-
evaluate(expr: string): any;
|
3158
|
+
evaluate(expr: string | string[]): any;
|
3159
3159
|
get(variable: string): any;
|
3160
3160
|
getAll(): { [key: string]: any };
|
3161
3161
|
set: (variable: string, value: any) => void;
|
@@ -4303,8 +4303,8 @@ declare namespace math {
|
|
4303
4303
|
|
4304
4304
|
/**
|
4305
4305
|
* Create the cartesian product of two (multi)sets. Multi-dimension
|
4306
|
-
* arrays will be converted to single-dimension arrays
|
4307
|
-
* operation.
|
4306
|
+
* arrays will be converted to single-dimension arrays and the values
|
4307
|
+
* will be sorted in ascending order before the operation.
|
4308
4308
|
* @param a2 A (multi)set
|
4309
4309
|
*/
|
4310
4310
|
setCartesian(a2: MathArray | Matrix): MathJsChain;
|