mathjs 7.5.1 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY.md +7 -0
- package/dist/math.js +123 -29
- package/dist/math.min.js +3 -3
- package/dist/math.min.map +1 -1
- package/docs/datatypes/units.md +21 -0
- package/docs/reference/functions/rotate.md +47 -0
- package/docs/reference/functions/rotationMatrix.md +1 -1
- package/docs/reference/functions.md +1 -0
- package/es/entry/dependenciesAny/dependenciesRotate.generated.js +14 -0
- package/es/entry/dependenciesAny.generated.js +1 -0
- package/es/entry/impureFunctionsAny.generated.js +24 -23
- package/es/entry/pureFunctionsAny.generated.js +10 -5
- package/es/expression/embeddedDocs/embeddedDocs.js +2 -0
- package/es/expression/embeddedDocs/function/matrix/rotate.js +8 -0
- package/es/expression/node/FunctionNode.js +1 -1
- package/es/expression/node/Node.js +2 -2
- package/es/factoriesAny.js +1 -0
- package/es/function/matrix/rotate.js +78 -0
- package/es/function/matrix/rotationMatrix.js +5 -4
- package/es/function/special/erf.js +1 -0
- package/es/plain/number/constants.js +1 -1
- package/es/plain/number/probability.js +1 -0
- package/es/type/unit/Unit.js +17 -18
- package/es/version.js +1 -1
- package/examples/bignumbers.js +2 -0
- package/lib/entry/dependenciesAny/dependenciesRotate.generated.js +26 -0
- package/lib/entry/dependenciesAny.generated.js +8 -0
- package/lib/entry/impureFunctionsAny.generated.js +27 -26
- package/lib/entry/mainAny.js +5 -0
- package/lib/entry/mainNumber.js +5 -0
- package/lib/entry/pureFunctionsAny.generated.js +14 -8
- package/lib/expression/embeddedDocs/embeddedDocs.js +3 -0
- package/lib/expression/embeddedDocs/function/matrix/rotate.js +15 -0
- package/lib/expression/node/FunctionNode.js +1 -1
- package/lib/expression/node/Node.js +2 -2
- package/lib/factoriesAny.js +8 -0
- package/lib/function/matrix/rotate.js +88 -0
- package/lib/function/matrix/rotationMatrix.js +5 -4
- package/lib/function/special/erf.js +1 -0
- package/lib/header.js +2 -2
- package/lib/plain/bignumber/index.js +1 -0
- package/lib/plain/number/constants.js +2 -1
- package/lib/plain/number/index.js +9 -0
- package/lib/plain/number/probability.js +1 -0
- package/lib/type/unit/Unit.js +17 -18
- package/lib/version.js +1 -1
- package/package.json +9 -9
- package/src/core/function/import.js +2 -2
- package/src/entry/dependenciesAny/dependenciesRotate.generated.js +15 -0
- package/src/entry/dependenciesAny.generated.js +1 -0
- package/src/entry/impureFunctionsAny.generated.js +20 -18
- package/src/entry/pureFunctionsAny.generated.js +7 -5
- package/src/expression/embeddedDocs/embeddedDocs.js +2 -0
- package/src/expression/embeddedDocs/function/matrix/rotate.js +19 -0
- package/src/expression/node/FunctionNode.js +1 -1
- package/src/expression/node/Node.js +2 -1
- package/src/factoriesAny.js +1 -0
- package/src/function/matrix/rotate.js +79 -0
- package/src/function/matrix/rotationMatrix.js +5 -4
- package/src/function/special/erf.js +2 -0
- package/src/plain/number/constants.js +1 -1
- package/src/plain/number/probability.js +2 -0
- package/src/type/unit/Unit.js +18 -21
- package/src/version.js +1 -1
package/HISTORY.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# History
|
2
2
|
|
3
|
+
# 2020-11-02, version 7.6.0
|
4
|
+
|
5
|
+
- Implemented function `rotate(w, theta)`. See #1992, #1160. Thanks @rnd-debug.
|
6
|
+
- Implemented support for custom characters in Units via `Unit.isValidAlpha`.
|
7
|
+
See #1663, #2000. Thanks @rnd-debug.
|
8
|
+
|
9
|
+
|
3
10
|
# 2020-10-10, version 7.5.1
|
4
11
|
|
5
12
|
- Fix object pollution vulnerability in `math.config`. Thanks Snyk.
|
package/dist/math.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 7.
|
10
|
-
* @date 2020-
|
9
|
+
* @version 7.6.0
|
10
|
+
* @date 2020-11-02
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2020 Jos de Jong <wjosdejong@gmail.com>
|
@@ -11733,6 +11733,7 @@ __webpack_require__.d(__webpack_exports__, "createOnes", function() { return /*
|
|
11733
11733
|
__webpack_require__.d(__webpack_exports__, "createRange", function() { return /* reexport */ range_createRange; });
|
11734
11734
|
__webpack_require__.d(__webpack_exports__, "createReshape", function() { return /* reexport */ createReshape; });
|
11735
11735
|
__webpack_require__.d(__webpack_exports__, "createResize", function() { return /* reexport */ createResize; });
|
11736
|
+
__webpack_require__.d(__webpack_exports__, "createRotate", function() { return /* reexport */ createRotate; });
|
11736
11737
|
__webpack_require__.d(__webpack_exports__, "createRotationMatrix", function() { return /* reexport */ createRotationMatrix; });
|
11737
11738
|
__webpack_require__.d(__webpack_exports__, "createRow", function() { return /* reexport */ createRow; });
|
11738
11739
|
__webpack_require__.d(__webpack_exports__, "createSize", function() { return /* reexport */ createSize; });
|
@@ -25694,6 +25695,85 @@ var createResize = /* #__PURE__ */Object(factory["a" /* factory */])(resize_name
|
|
25694
25695
|
}
|
25695
25696
|
}
|
25696
25697
|
});
|
25698
|
+
// CONCATENATED MODULE: ./src/function/matrix/rotate.js
|
25699
|
+
|
25700
|
+
|
25701
|
+
var rotate_name = 'rotate';
|
25702
|
+
var rotate_dependencies = ['typed', 'multiply', 'rotationMatrix'];
|
25703
|
+
var createRotate = /* #__PURE__ */Object(factory["a" /* factory */])(rotate_name, rotate_dependencies, function (_ref) {
|
25704
|
+
var typed = _ref.typed,
|
25705
|
+
multiply = _ref.multiply,
|
25706
|
+
rotationMatrix = _ref.rotationMatrix;
|
25707
|
+
|
25708
|
+
/**
|
25709
|
+
* Rotate a vector of size 1x2 counter-clockwise by a given angle
|
25710
|
+
* Rotate a vector of size 1x3 counter-clockwise by a given angle around the given axis
|
25711
|
+
*
|
25712
|
+
* Syntax:
|
25713
|
+
*
|
25714
|
+
* math.rotate(w, theta)
|
25715
|
+
* math.rotate(w, theta, v)
|
25716
|
+
*
|
25717
|
+
* Examples:
|
25718
|
+
*
|
25719
|
+
* math.rotate([11, 12], math.pi / 2) // returns matrix([-12, 11])
|
25720
|
+
* math.rotate(matrix([11, 12]), math.pi / 2) // returns matrix([-12, 11])
|
25721
|
+
*
|
25722
|
+
* math.rotate([1, 0, 0], unit('90deg'), [0, 0, 1]) // returns matrix([0, 1, 0])
|
25723
|
+
* math.rotate(matrix([1, 0, 0]), unit('90deg'), [0, 0, 1]) // returns matrix([0, 1, 0])
|
25724
|
+
*
|
25725
|
+
* math.rotate([1, 0], math.complex(1 + i)) // returns matrix([cos(1 + i) - sin(1 + i), sin(1 + i) + cos(1 + i)])
|
25726
|
+
*
|
25727
|
+
* See also:
|
25728
|
+
*
|
25729
|
+
* matrix, rotationMatrix
|
25730
|
+
*
|
25731
|
+
* @param {Array | Matrix} w Vector to rotate
|
25732
|
+
* @param {number | BigNumber | Complex | Unit} theta Rotation angle
|
25733
|
+
* @param {Array | Matrix} [v] Rotation axis
|
25734
|
+
* @return {Array | Matrix} Multiplication of the rotation matrix and w
|
25735
|
+
*/
|
25736
|
+
return typed(rotate_name, {
|
25737
|
+
'Array , number | BigNumber | Complex | Unit': function ArrayNumberBigNumberComplexUnit(w, theta) {
|
25738
|
+
_validateSize(w, 2);
|
25739
|
+
|
25740
|
+
var matrixRes = multiply(rotationMatrix(theta), w);
|
25741
|
+
return matrixRes.toArray();
|
25742
|
+
},
|
25743
|
+
'Matrix , number | BigNumber | Complex | Unit': function MatrixNumberBigNumberComplexUnit(w, theta) {
|
25744
|
+
_validateSize(w, 2);
|
25745
|
+
|
25746
|
+
return multiply(rotationMatrix(theta), w);
|
25747
|
+
},
|
25748
|
+
'Array, number | BigNumber | Complex | Unit, Array | Matrix': function ArrayNumberBigNumberComplexUnitArrayMatrix(w, theta, v) {
|
25749
|
+
_validateSize(w, 3);
|
25750
|
+
|
25751
|
+
var matrixRes = multiply(rotationMatrix(theta, v), w);
|
25752
|
+
return matrixRes;
|
25753
|
+
},
|
25754
|
+
'Matrix, number | BigNumber | Complex | Unit, Array | Matrix': function MatrixNumberBigNumberComplexUnitArrayMatrix(w, theta, v) {
|
25755
|
+
_validateSize(w, 3);
|
25756
|
+
|
25757
|
+
return multiply(rotationMatrix(theta, v), w);
|
25758
|
+
}
|
25759
|
+
});
|
25760
|
+
|
25761
|
+
function _validateSize(v, expectedSize) {
|
25762
|
+
var actualSize = Array.isArray(v) ? Object(utils_array["a" /* arraySize */])(v) : v.size();
|
25763
|
+
|
25764
|
+
if (actualSize.length > 2) {
|
25765
|
+
throw new RangeError("Vector must be of dimensions 1x".concat(expectedSize));
|
25766
|
+
}
|
25767
|
+
|
25768
|
+
if (actualSize.length === 2 && actualSize[1] !== 1) {
|
25769
|
+
throw new RangeError("Vector must be of dimensions 1x".concat(expectedSize));
|
25770
|
+
}
|
25771
|
+
|
25772
|
+
if (actualSize[0] !== expectedSize) {
|
25773
|
+
throw new RangeError("Vector must be of dimensions 1x".concat(expectedSize));
|
25774
|
+
}
|
25775
|
+
}
|
25776
|
+
});
|
25697
25777
|
// CONCATENATED MODULE: ./src/function/matrix/rotationMatrix.js
|
25698
25778
|
|
25699
25779
|
|
@@ -25727,7 +25807,7 @@ var createRotationMatrix = /* #__PURE__ */Object(factory["a" /* factory */])(rot
|
|
25727
25807
|
* Examples:
|
25728
25808
|
*
|
25729
25809
|
* math.rotationMatrix(math.pi / 2) // returns [[0, -1], [1, 0]]
|
25730
|
-
* math.rotationMatrix(math.bignumber(
|
25810
|
+
* math.rotationMatrix(math.bignumber(1)) // returns [[bignumber(cos(1)), bignumber(-sin(1))], [bignumber(sin(1)), bignumber(cos(1))]]
|
25731
25811
|
* math.rotationMatrix(math.complex(1 + i)) // returns [[cos(1 + i), -sin(1 + i)], [sin(1 + i), cos(1 + i)]]
|
25732
25812
|
* math.rotationMatrix(math.unit('1rad')) // returns [[cos(1), -sin(1)], [sin(1), cos(1)]]
|
25733
25813
|
*
|
@@ -25763,12 +25843,13 @@ var createRotationMatrix = /* #__PURE__ */Object(factory["a" /* factory */])(rot
|
|
25763
25843
|
|
25764
25844
|
_validateVector(matrixV);
|
25765
25845
|
|
25766
|
-
return _rotationMatrix3x3(theta, matrixV,
|
25846
|
+
return _rotationMatrix3x3(theta, matrixV, undefined);
|
25767
25847
|
},
|
25768
25848
|
'number | BigNumber | Complex | Unit, Matrix': function numberBigNumberComplexUnitMatrix(theta, v) {
|
25769
25849
|
_validateVector(v);
|
25770
25850
|
|
25771
|
-
|
25851
|
+
var storageType = v.storage() || (config.matrix === 'Matrix' ? 'dense' : undefined);
|
25852
|
+
return _rotationMatrix3x3(theta, v, storageType);
|
25772
25853
|
},
|
25773
25854
|
'number | BigNumber | Complex | Unit, Array, string': function numberBigNumberComplexUnitArrayString(theta, v, format) {
|
25774
25855
|
var matrixV = matrix(v);
|
@@ -25845,7 +25926,7 @@ var createRotationMatrix = /* #__PURE__ */Object(factory["a" /* factory */])(rot
|
|
25845
25926
|
var normV = norm(v);
|
25846
25927
|
|
25847
25928
|
if (normV === 0) {
|
25848
|
-
|
25929
|
+
throw new RangeError('Rotation around zero vector');
|
25849
25930
|
}
|
25850
25931
|
|
25851
25932
|
var Big = Object(is["e" /* isBigNumber */])(theta) ? BigNumber : null;
|
@@ -26753,6 +26834,7 @@ var createZeros = /* #__PURE__ */Object(factory["a" /* factory */])(zeros_name,
|
|
26753
26834
|
}
|
26754
26835
|
}); // TODO: zeros contains almost the same code as ones. Reuse this?
|
26755
26836
|
// CONCATENATED MODULE: ./src/function/special/erf.js
|
26837
|
+
/* eslint-disable no-loss-of-precision */
|
26756
26838
|
|
26757
26839
|
|
26758
26840
|
|
@@ -33542,19 +33624,16 @@ var createUnitClass = /* #__PURE__ */Object(factory["a" /* factory */])(Unit_nam
|
|
33542
33624
|
function parseUnit() {
|
33543
33625
|
var unitName = ''; // Alphanumeric characters only; matches [a-zA-Z0-9]
|
33544
33626
|
|
33545
|
-
|
33546
|
-
|
33547
|
-
while (code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
33627
|
+
while (isDigit(c) || Unit.isValidAlpha(c)) {
|
33548
33628
|
unitName += c;
|
33549
33629
|
next();
|
33550
|
-
code = text.charCodeAt(index);
|
33551
33630
|
} // Must begin with [a-zA-Z]
|
33552
33631
|
|
33553
33632
|
|
33554
|
-
|
33633
|
+
var firstC = unitName.charAt(0);
|
33555
33634
|
|
33556
|
-
if (
|
33557
|
-
return unitName
|
33635
|
+
if (Unit.isValidAlpha(firstC)) {
|
33636
|
+
return unitName;
|
33558
33637
|
} else {
|
33559
33638
|
return null;
|
33560
33639
|
}
|
@@ -37009,24 +37088,26 @@ var createUnitClass = /* #__PURE__ */Object(factory["a" /* factory */])(Unit_nam
|
|
37009
37088
|
UNITS[_name2] = alias;
|
37010
37089
|
}
|
37011
37090
|
}
|
37091
|
+
/**
|
37092
|
+
* Checks if a character is a valid latin letter (upper or lower case).
|
37093
|
+
* Note that this function can be overridden, for example to allow support of other alphabets.
|
37094
|
+
* @param {string} c Tested character
|
37095
|
+
*/
|
37012
37096
|
|
37013
|
-
function assertUnitNameIsValid(name) {
|
37014
|
-
for (var i = 0; i < name.length; i++) {
|
37015
|
-
var _c = name.charAt(i);
|
37016
37097
|
|
37017
|
-
|
37018
|
-
|
37019
|
-
|
37098
|
+
Unit.isValidAlpha = function isValidAlpha(c) {
|
37099
|
+
return /^[a-zA-Z]$/.test(c);
|
37100
|
+
};
|
37020
37101
|
|
37021
|
-
|
37022
|
-
|
37023
|
-
|
37102
|
+
function assertUnitNameIsValid(name) {
|
37103
|
+
for (var i = 0; i < name.length; i++) {
|
37104
|
+
c = name.charAt(i);
|
37024
37105
|
|
37025
|
-
if (i === 0 && !isValidAlpha(
|
37106
|
+
if (i === 0 && !Unit.isValidAlpha(c)) {
|
37026
37107
|
throw new Error('Invalid unit name (must begin with alpha character): "' + name + '"');
|
37027
37108
|
}
|
37028
37109
|
|
37029
|
-
if (i > 0 && !(isValidAlpha(
|
37110
|
+
if (i > 0 && !(Unit.isValidAlpha(c) || isDigit(c))) {
|
37030
37111
|
throw new Error('Invalid unit name (only alphanumeric characters are allowed): "' + name + '"');
|
37031
37112
|
}
|
37032
37113
|
}
|
@@ -40614,8 +40695,8 @@ var createNode = /* #__PURE__ */Object(factory["a" /* factory */])(Node_name, No
|
|
40614
40695
|
|
40615
40696
|
Node.prototype.traverse = function (callback) {
|
40616
40697
|
// execute callback for itself
|
40617
|
-
|
40618
|
-
// recursively traverse over all childs of a node
|
40698
|
+
// eslint-disable-next-line
|
40699
|
+
callback(this, null, null); // recursively traverse over all childs of a node
|
40619
40700
|
|
40620
40701
|
function _traverse(node, callback) {
|
40621
40702
|
node.forEach(function (child, path, parent) {
|
@@ -45745,7 +45826,7 @@ var createFunctionNode = /* #__PURE__ */Object(factory["a" /* factory */])(Funct
|
|
45745
45826
|
var latex = ''; // Match everything of the form ${identifier} or ${identifier[2]} or $$
|
45746
45827
|
// while submatching identifier and 2 (in the second case)
|
45747
45828
|
|
45748
|
-
var regex =
|
45829
|
+
var regex = /\$(?:\{([a-z_][a-z_0-9]*)(?:\[([0-9]+)\])?\}|\$)/gi;
|
45749
45830
|
var inputPos = 0; // position in the input string
|
45750
45831
|
|
45751
45832
|
var match;
|
@@ -52948,6 +53029,15 @@ var rotationMatrixDocs = {
|
|
52948
53029
|
examples: ['rotationMatrix(pi / 2)', 'rotationMatrix(unit("45deg"), [0, 0, 1])', 'rotationMatrix(1, matrix([0, 0, 1]), "sparse")'],
|
52949
53030
|
seealso: ['cos', 'sin']
|
52950
53031
|
};
|
53032
|
+
// CONCATENATED MODULE: ./src/expression/embeddedDocs/function/matrix/rotate.js
|
53033
|
+
var rotateDocs = {
|
53034
|
+
name: 'rotate',
|
53035
|
+
category: 'Matrix',
|
53036
|
+
syntax: ['rotate(w, theta)', 'rotate(w, theta, v)'],
|
53037
|
+
description: 'Returns a 2-D rotation matrix (2x2) for a given angle (in radians). ' + 'Returns a 2-D rotation matrix (3x3) of a given angle (in radians) around given axis.',
|
53038
|
+
examples: ['rotate([1, 0], math.pi / 2)', 'rotate(matrix([1, 0]), unit("35deg"))', 'rotate([1, 0, 0], unit("90deg"), [0, 0, 1])', 'rotate(matrix([1, 0, 0]), unit("90deg"), matrix([0, 0, 1]))'],
|
53039
|
+
seealso: ['matrix', 'rotationMatrix']
|
53040
|
+
};
|
52951
53041
|
// CONCATENATED MODULE: ./src/expression/embeddedDocs/embeddedDocs.js
|
52952
53042
|
|
52953
53043
|
|
@@ -53164,6 +53254,7 @@ var rotationMatrixDocs = {
|
|
53164
53254
|
|
53165
53255
|
|
53166
53256
|
|
53257
|
+
|
53167
53258
|
|
53168
53259
|
|
53169
53260
|
var embeddedDocs = {
|
@@ -53509,6 +53600,7 @@ var embeddedDocs = {
|
|
53509
53600
|
range: rangeDocs,
|
53510
53601
|
resize: resizeDocs,
|
53511
53602
|
reshape: reshapeDocs,
|
53603
|
+
rotate: rotateDocs,
|
53512
53604
|
rotationMatrix: rotationMatrixDocs,
|
53513
53605
|
row: rowDocs,
|
53514
53606
|
size: sizeDocs,
|
@@ -56512,6 +56604,7 @@ function combinationsWithRep_isPositiveInteger(n) {
|
|
56512
56604
|
return n.isInteger() && n.gte(0);
|
56513
56605
|
}
|
56514
56606
|
// CONCATENATED MODULE: ./src/plain/number/probability.js
|
56607
|
+
/* eslint-disable no-loss-of-precision */
|
56515
56608
|
|
56516
56609
|
|
56517
56610
|
function gammaNumber(n) {
|
@@ -60661,13 +60754,13 @@ var createReplacer = /* #__PURE__ */Object(factory["a" /* factory */])(replacer_
|
|
60661
60754
|
};
|
60662
60755
|
});
|
60663
60756
|
// CONCATENATED MODULE: ./src/version.js
|
60664
|
-
var version = '7.
|
60757
|
+
var version = '7.6.0'; // Note: This file is automatically generated when building math.js.
|
60665
60758
|
// Changes made in this file will be overwritten.
|
60666
60759
|
// CONCATENATED MODULE: ./src/plain/number/constants.js
|
60667
60760
|
var constants_pi = Math.PI;
|
60668
60761
|
var tau = 2 * Math.PI;
|
60669
60762
|
var constants_e = Math.E;
|
60670
|
-
var constants_phi = 1.
|
60763
|
+
var constants_phi = 1.6180339887498948; // eslint-disable-line no-loss-of-precision
|
60671
60764
|
// CONCATENATED MODULE: ./src/constants.js
|
60672
60765
|
|
60673
60766
|
|
@@ -62045,6 +62138,7 @@ var createVarianceTransform = /* #__PURE__ */Object(factory["a" /* factory */])(
|
|
62045
62138
|
|
62046
62139
|
|
62047
62140
|
|
62141
|
+
|
62048
62142
|
|
62049
62143
|
|
62050
62144
|
/***/ }),
|