mathjs 5.9.0 → 5.10.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mathjs might be problematic. Click here for more details.
- package/HISTORY.md +26 -1
- package/dist/math.js +52 -30
- package/dist/math.min.js +5 -5
- package/dist/math.min.map +1 -1
- package/docs/reference/functions/column.md +3 -3
- package/docs/reference/functions/row.md +3 -3
- package/docs/reference/functions.md +2 -2
- package/lib/expression/embeddedDocs/function/matrix/column.js +2 -2
- package/lib/expression/embeddedDocs/function/matrix/row.js +2 -2
- package/lib/function/matrix/column.js +3 -3
- package/lib/function/matrix/row.js +3 -3
- package/lib/header.js +2 -3
- package/lib/utils/bignumber/formatter.js +8 -3
- package/lib/utils/number.js +8 -3
- package/lib/version.js +1 -1
- package/package.json +17 -15
- package/src/expression/embeddedDocs/function/matrix/column.js +4 -2
- package/src/expression/embeddedDocs/function/matrix/row.js +4 -2
- package/src/function/matrix/column.js +3 -3
- package/src/function/matrix/row.js +3 -3
- package/src/utils/bignumber/formatter.js +7 -4
- package/src/utils/number.js +10 -3
- package/src/version.js +1 -1
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
# Function column
|
4
4
|
|
5
|
-
Return column
|
5
|
+
Return a column from a Matrix.
|
6
6
|
|
7
7
|
|
8
8
|
## Syntax
|
9
9
|
|
10
10
|
```js
|
11
|
-
math.column(value, index)
|
11
|
+
math.column(value, index)
|
12
12
|
```
|
13
13
|
|
14
14
|
### Parameters
|
@@ -30,7 +30,7 @@ Array | Matrix | The retrieved column
|
|
30
30
|
```js
|
31
31
|
// get a column
|
32
32
|
const d = [[1, 2], [3, 4]]
|
33
|
-
math.column(d, 1)
|
33
|
+
math.column(d, 1) // returns [2, 4]
|
34
34
|
```
|
35
35
|
|
36
36
|
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
# Function row
|
4
4
|
|
5
|
-
Return row
|
5
|
+
Return a row from a Matrix.
|
6
6
|
|
7
7
|
|
8
8
|
## Syntax
|
9
9
|
|
10
10
|
```js
|
11
|
-
math.row(value, index)
|
11
|
+
math.row(value, index)
|
12
12
|
```
|
13
13
|
|
14
14
|
### Parameters
|
@@ -30,7 +30,7 @@ Array | Matrix | The retrieved row
|
|
30
30
|
```js
|
31
31
|
// get a row
|
32
32
|
const d = [[1, 2], [3, 4]]
|
33
|
-
math.row(d, 1)
|
33
|
+
math.row(d, 1) // returns [3, 4]
|
34
34
|
```
|
35
35
|
|
36
36
|
|
@@ -140,7 +140,7 @@ Function | Description
|
|
140
140
|
Function | Description
|
141
141
|
---- | -----------
|
142
142
|
[math.apply(A, dim, callback)](functions/apply.md) | Apply a function that maps an array to a scalar along a given axis of a matrix or array.
|
143
|
-
[math.column(value, index)](functions/column.md) | Return column
|
143
|
+
[math.column(value, index)](functions/column.md) | Return a column from a Matrix.
|
144
144
|
[math.concat(a, b, c, ... [, dim])](functions/concat.md) | Concatenate two or more matrices.
|
145
145
|
[math.cross(x, y)](functions/cross.md) | Calculate the cross product for two vectors in three dimensional space.
|
146
146
|
[math.ctranspose(x)](functions/ctranspose.md) | Transpose and complex conjugate a matrix.
|
@@ -161,7 +161,7 @@ Function | Description
|
|
161
161
|
[math.range(start, end [, step])](functions/range.md) | Create an array from a range.
|
162
162
|
[math.reshape(x, sizes)](functions/reshape.md) | Reshape a multi dimensional array to fit the specified dimensions.
|
163
163
|
[math.resize(x, size [, defaultValue])](functions/resize.md) | Resize a matrix.
|
164
|
-
[math.row(value, index)](functions/row.md) | Return row
|
164
|
+
[math.row(value, index)](functions/row.md) | Return a row from a Matrix.
|
165
165
|
[math.size(x)](functions/size.md) | Calculate the size of a matrix or scalar.
|
166
166
|
[math.sort(x)](functions/sort.md) | Sort the items in a matrix.
|
167
167
|
[X = math.sqrtm(A)](functions/sqrtm.md) | Calculate the principal square root of a square matrix.
|
@@ -4,7 +4,7 @@ module.exports = {
|
|
4
4
|
'name': 'column',
|
5
5
|
'category': 'Matrix',
|
6
6
|
'syntax': ['column(x, index)'],
|
7
|
-
'description': 'Return a column from a matrix or array.
|
8
|
-
'examples': ['
|
7
|
+
'description': 'Return a column from a matrix or array.',
|
8
|
+
'examples': ['A = [[1, 2], [3, 4]]', 'column(A, 1)', 'column(A, 2)'],
|
9
9
|
'seealso': ['row']
|
10
10
|
};
|
@@ -4,7 +4,7 @@ module.exports = {
|
|
4
4
|
'name': 'row',
|
5
5
|
'category': 'Matrix',
|
6
6
|
'syntax': ['row(x, index)'],
|
7
|
-
'description': 'Return a row from a matrix or array.
|
8
|
-
'examples': ['
|
7
|
+
'description': 'Return a row from a matrix or array.',
|
8
|
+
'examples': ['A = [[1, 2], [3, 4]]', 'row(A, 1)', 'row(A, 2)'],
|
9
9
|
'seealso': ['column']
|
10
10
|
};
|
@@ -9,17 +9,17 @@ function factory(type, config, load, typed) {
|
|
9
9
|
var matrix = load(require('../../type/matrix/function/matrix'));
|
10
10
|
var range = load(require('./range'));
|
11
11
|
/**
|
12
|
-
* Return column
|
12
|
+
* Return a column from a Matrix.
|
13
13
|
*
|
14
14
|
* Syntax:
|
15
15
|
*
|
16
|
-
* math.column(value, index)
|
16
|
+
* math.column(value, index)
|
17
17
|
*
|
18
18
|
* Example:
|
19
19
|
*
|
20
20
|
* // get a column
|
21
21
|
* const d = [[1, 2], [3, 4]]
|
22
|
-
* math.column(d, 1)
|
22
|
+
* math.column(d, 1) // returns [2, 4]
|
23
23
|
*
|
24
24
|
* See also:
|
25
25
|
*
|
@@ -9,17 +9,17 @@ function factory(type, config, load, typed) {
|
|
9
9
|
var matrix = load(require('../../type/matrix/function/matrix'));
|
10
10
|
var range = load(require('./range'));
|
11
11
|
/**
|
12
|
-
* Return row
|
12
|
+
* Return a row from a Matrix.
|
13
13
|
*
|
14
14
|
* Syntax:
|
15
15
|
*
|
16
|
-
* math.row(value, index)
|
16
|
+
* math.row(value, index)
|
17
17
|
*
|
18
18
|
* Example:
|
19
19
|
*
|
20
20
|
* // get a row
|
21
21
|
* const d = [[1, 2], [3, 4]]
|
22
|
-
* math.row(d, 1)
|
22
|
+
* math.row(d, 1) // returns [3, 4]
|
23
23
|
*
|
24
24
|
* See also:
|
25
25
|
*
|
package/lib/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
|
-
* @date
|
9
|
+
* @version 5.10.3
|
10
|
+
* @date 2019-05-18
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2019 Jos de Jong <wjosdejong@gmail.com>
|
@@ -24,4 +24,3 @@
|
|
24
24
|
* License for the specific language governing permissions and limitations under
|
25
25
|
* the License.
|
26
26
|
*/
|
27
|
-
"use strict";
|
@@ -172,9 +172,14 @@ exports.toEngineering = function (value, precision) {
|
|
172
172
|
var e = value.e;
|
173
173
|
var newExp = e % 3 === 0 ? e : e < 0 ? e - 3 - e % 3 : e - e % 3; // find difference in exponents, and calculate the value without exponent
|
174
174
|
|
175
|
-
var
|
176
|
-
var
|
177
|
-
|
175
|
+
var valueWithoutExp = value.mul(Math.pow(10, -newExp));
|
176
|
+
var valueStr = valueWithoutExp.toPrecision(precision);
|
177
|
+
|
178
|
+
if (valueStr.indexOf('e') !== -1) {
|
179
|
+
valueStr = valueWithoutExp.toString();
|
180
|
+
}
|
181
|
+
|
182
|
+
return valueStr + 'e' + (e >= 0 ? '+' : '') + newExp.toString();
|
178
183
|
};
|
179
184
|
/**
|
180
185
|
* Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3'
|
package/lib/utils/number.js
CHANGED
@@ -255,20 +255,25 @@ exports.toEngineering = function (value, precision) {
|
|
255
255
|
|
256
256
|
if (exports.isNumber(precision)) {
|
257
257
|
// add zeroes to give correct sig figs
|
258
|
-
|
258
|
+
while (precision > c.length || e - newExp + 1 > c.length) {
|
259
|
+
c.push(0);
|
260
|
+
}
|
259
261
|
} else {
|
260
262
|
// concatenate coefficients with necessary zeros
|
261
263
|
var significandsDiff = e >= 0 ? e : Math.abs(newExp); // add zeros if necessary (for ex: 1e+8)
|
262
264
|
|
263
|
-
|
265
|
+
while (c.length - 1 < significandsDiff) {
|
266
|
+
c.push(0);
|
267
|
+
}
|
264
268
|
} // find difference in exponents
|
265
269
|
|
266
270
|
|
267
271
|
var expDiff = Math.abs(e - newExp);
|
268
272
|
var decimalIdx = 1; // push decimal index over by expDiff times
|
269
273
|
|
270
|
-
while (
|
274
|
+
while (expDiff > 0) {
|
271
275
|
decimalIdx++;
|
276
|
+
expDiff--;
|
272
277
|
} // if all coefficient values are zero after the decimal point and precision is unset, don't add a decimal value.
|
273
278
|
// otherwise concat with the rest of the coefficients
|
274
279
|
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mathjs",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.10.3",
|
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
|
"contributors": [
|
@@ -52,7 +52,8 @@
|
|
52
52
|
"Karl Lew (https://github.com/firepick1)",
|
53
53
|
"Kenan Yildirim (https://github.com/KenanY)",
|
54
54
|
"Keunhong Park (https://github.com/void42)",
|
55
|
-
"
|
55
|
+
"Keunhong Park (https://github.com/kevjin)",
|
56
|
+
"Kevin J (https://github.com/kv-kunalvyas)",
|
56
57
|
"Marcus Andre (https://github.com/marcusandre)",
|
57
58
|
"Horatiu Lazu (https://github.com/MathBunny)",
|
58
59
|
"Mathias Polligkeit (https://github.com/woylie)",
|
@@ -112,7 +113,7 @@
|
|
112
113
|
],
|
113
114
|
"dependencies": {
|
114
115
|
"complex.js": "2.0.11",
|
115
|
-
"decimal.js": "10.
|
116
|
+
"decimal.js": "10.2.0",
|
116
117
|
"escape-latex": "1.2.0",
|
117
118
|
"fraction.js": "4.0.12",
|
118
119
|
"javascript-natural-sort": "0.7.1",
|
@@ -121,21 +122,22 @@
|
|
121
122
|
"typed-function": "1.1.0"
|
122
123
|
},
|
123
124
|
"devDependencies": {
|
124
|
-
"@babel/core": "7.4.
|
125
|
+
"@babel/core": "7.4.4",
|
125
126
|
"@babel/plugin-transform-object-assign": "7.2.0",
|
126
|
-
"@babel/preset-env": "7.4.
|
127
|
-
"@babel/register": "7.4.
|
128
|
-
"babel-loader": "8.0.
|
127
|
+
"@babel/preset-env": "7.4.4",
|
128
|
+
"@babel/register": "7.4.4",
|
129
|
+
"babel-loader": "8.0.6",
|
129
130
|
"benchmark": "2.1.4",
|
130
|
-
"codecov": "3.
|
131
|
+
"codecov": "3.5.0",
|
132
|
+
"del": "4.1.1",
|
131
133
|
"expr-eval": "1.2.2",
|
132
|
-
"glob": "7.1.
|
133
|
-
"gulp": "4.0.
|
134
|
+
"glob": "7.1.4",
|
135
|
+
"gulp": "4.0.2",
|
134
136
|
"gulp-babel": "8.0.0",
|
135
137
|
"gulp-util": "3.0.8",
|
136
138
|
"istanbul": "0.4.5",
|
137
139
|
"jsep": "0.3.4",
|
138
|
-
"karma": "4.0
|
140
|
+
"karma": "4.1.0",
|
139
141
|
"karma-browserstack-launcher": "1.5.1",
|
140
142
|
"karma-firefox-launcher": "1.1.0",
|
141
143
|
"karma-mocha": "1.3.0",
|
@@ -143,22 +145,22 @@
|
|
143
145
|
"karma-webpack": "3.0.5",
|
144
146
|
"math-expression-evaluator": "1.2.17",
|
145
147
|
"mkdirp": "0.5.1",
|
146
|
-
"mocha": "6.1.
|
148
|
+
"mocha": "6.1.4",
|
147
149
|
"ndarray": "1.0.18",
|
148
150
|
"ndarray-determinant": "1.0.0",
|
149
151
|
"ndarray-gemm": "1.0.0",
|
150
152
|
"ndarray-ops": "1.2.2",
|
151
153
|
"ndarray-pack": "1.2.1",
|
152
154
|
"numericjs": "1.2.6",
|
153
|
-
"nyc": "
|
155
|
+
"nyc": "14.1.1",
|
154
156
|
"pad-right": "0.2.2",
|
155
157
|
"q": "1.5.1",
|
156
158
|
"standard": "12.0.1",
|
157
159
|
"sylvester": "0.0.21",
|
158
160
|
"tar": "4.4.8",
|
159
|
-
"uglify-js": "3.5.
|
161
|
+
"uglify-js": "3.5.13",
|
160
162
|
"underscore": "1.9.1",
|
161
|
-
"webpack": "4.
|
163
|
+
"webpack": "4.31.0",
|
162
164
|
"zeros": "1.0.0"
|
163
165
|
},
|
164
166
|
"main": "./index",
|
@@ -4,9 +4,11 @@ module.exports = {
|
|
4
4
|
'syntax': [
|
5
5
|
'column(x, index)'
|
6
6
|
],
|
7
|
-
'description': 'Return a column from a matrix or array.
|
7
|
+
'description': 'Return a column from a matrix or array.',
|
8
8
|
'examples': [
|
9
|
-
'
|
9
|
+
'A = [[1, 2], [3, 4]]',
|
10
|
+
'column(A, 1)',
|
11
|
+
'column(A, 2)'
|
10
12
|
],
|
11
13
|
'seealso': ['row']
|
12
14
|
}
|
@@ -4,9 +4,11 @@ module.exports = {
|
|
4
4
|
'syntax': [
|
5
5
|
'row(x, index)'
|
6
6
|
],
|
7
|
-
'description': 'Return a row from a matrix or array.
|
7
|
+
'description': 'Return a row from a matrix or array.',
|
8
8
|
'examples': [
|
9
|
-
'
|
9
|
+
'A = [[1, 2], [3, 4]]',
|
10
|
+
'row(A, 1)',
|
11
|
+
'row(A, 2)'
|
10
12
|
],
|
11
13
|
'seealso': ['column']
|
12
14
|
}
|
@@ -9,17 +9,17 @@ function factory (type, config, load, typed) {
|
|
9
9
|
const range = load(require('./range'))
|
10
10
|
|
11
11
|
/**
|
12
|
-
* Return column
|
12
|
+
* Return a column from a Matrix.
|
13
13
|
*
|
14
14
|
* Syntax:
|
15
15
|
*
|
16
|
-
* math.column(value, index)
|
16
|
+
* math.column(value, index)
|
17
17
|
*
|
18
18
|
* Example:
|
19
19
|
*
|
20
20
|
* // get a column
|
21
21
|
* const d = [[1, 2], [3, 4]]
|
22
|
-
* math.column(d, 1)
|
22
|
+
* math.column(d, 1) // returns [2, 4]
|
23
23
|
*
|
24
24
|
* See also:
|
25
25
|
*
|
@@ -9,17 +9,17 @@ function factory (type, config, load, typed) {
|
|
9
9
|
const range = load(require('./range'))
|
10
10
|
|
11
11
|
/**
|
12
|
-
* Return row
|
12
|
+
* Return a row from a Matrix.
|
13
13
|
*
|
14
14
|
* Syntax:
|
15
15
|
*
|
16
|
-
* math.row(value, index)
|
16
|
+
* math.row(value, index)
|
17
17
|
*
|
18
18
|
* Example:
|
19
19
|
*
|
20
20
|
* // get a row
|
21
21
|
* const d = [[1, 2], [3, 4]]
|
22
|
-
* math.row(d, 1)
|
22
|
+
* math.row(d, 1) // returns [3, 4]
|
23
23
|
*
|
24
24
|
* See also:
|
25
25
|
*
|
@@ -174,11 +174,14 @@ exports.toEngineering = function (value, precision) {
|
|
174
174
|
const newExp = e % 3 === 0 ? e : (e < 0 ? (e - 3) - (e % 3) : e - (e % 3))
|
175
175
|
|
176
176
|
// find difference in exponents, and calculate the value without exponent
|
177
|
-
const
|
178
|
-
const valueWithoutExp = value.mul(Math.pow(10, expDiff - e))
|
177
|
+
const valueWithoutExp = value.mul(Math.pow(10, -newExp))
|
179
178
|
|
180
|
-
|
181
|
-
|
179
|
+
let valueStr = valueWithoutExp.toPrecision(precision)
|
180
|
+
if (valueStr.indexOf('e') !== -1) {
|
181
|
+
valueStr = valueWithoutExp.toString()
|
182
|
+
}
|
183
|
+
|
184
|
+
return valueStr + 'e' + (e >= 0 ? '+' : '') + newExp.toString()
|
182
185
|
}
|
183
186
|
|
184
187
|
/**
|
package/src/utils/number.js
CHANGED
@@ -263,13 +263,17 @@ exports.toEngineering = function (value, precision) {
|
|
263
263
|
|
264
264
|
if (exports.isNumber(precision)) {
|
265
265
|
// add zeroes to give correct sig figs
|
266
|
-
|
266
|
+
while (precision > c.length || (e - newExp) + 1 > c.length) {
|
267
|
+
c.push(0)
|
268
|
+
}
|
267
269
|
} else {
|
268
270
|
// concatenate coefficients with necessary zeros
|
269
271
|
const significandsDiff = e >= 0 ? e : Math.abs(newExp)
|
270
272
|
|
271
273
|
// add zeros if necessary (for ex: 1e+8)
|
272
|
-
|
274
|
+
while (c.length - 1 < significandsDiff) {
|
275
|
+
c.push(0)
|
276
|
+
}
|
273
277
|
}
|
274
278
|
|
275
279
|
// find difference in exponents
|
@@ -278,7 +282,10 @@ exports.toEngineering = function (value, precision) {
|
|
278
282
|
let decimalIdx = 1
|
279
283
|
|
280
284
|
// push decimal index over by expDiff times
|
281
|
-
while (
|
285
|
+
while (expDiff > 0) {
|
286
|
+
decimalIdx++
|
287
|
+
expDiff--
|
288
|
+
}
|
282
289
|
|
283
290
|
// if all coefficient values are zero after the decimal point and precision is unset, don't add a decimal value.
|
284
291
|
// otherwise concat with the rest of the coefficients
|
package/src/version.js
CHANGED