mathjs 5.0.0 → 5.0.4
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 +48 -1
- package/README.md +2 -1
- package/dist/math.js +20114 -20090
- package/dist/math.min.js +7 -7
- package/dist/math.min.map +1 -1
- package/docs/core/configuration.md +1 -1
- package/docs/datatypes/numbers.md +1 -1
- package/docs/datatypes/units.md +1 -1
- package/docs/expressions/algebra.md +25 -1
- package/docs/getting_started.md +2 -2
- package/docs/reference/functions/format.md +2 -2
- package/docs/reference/functions/qr.md +2 -1
- package/docs/reference/functions/rationalize.md +13 -10
- package/docs/reference/functions/stirlingS2.md +1 -1
- package/docs/reference/functions/typeof.md +13 -13
- package/examples/advanced/add_new_datatypes/MyType.js +0 -10
- package/examples/advanced/add_new_datatypes/index.js +2 -6
- package/examples/browser/rocket_trajectory_optimization.html +2 -2
- package/lib/constants.js +3 -1
- package/lib/core/function/import.js +15 -2
- package/lib/core/typed.js +1 -1
- package/lib/expression/node/FunctionNode.js +5 -4
- package/lib/expression/parse.js +429 -466
- package/lib/function/algebra/decomposition/qr.js +1 -1
- package/lib/function/algebra/rationalize.js +41 -45
- package/lib/function/algebra/simplify/resolve.js +1 -1
- package/lib/function/algebra/simplify/simplifyCore.js +3 -3
- package/lib/function/algebra/simplify/util.js +1 -1
- package/lib/function/algebra/simplify.js +5 -0
- package/lib/function/combinatorics/stirlingS2.js +1 -1
- package/lib/function/probability/combinations.js +11 -10
- package/lib/function/probability/gamma.js +5 -13
- package/lib/function/probability/permutations.js +2 -12
- package/lib/function/probability/product.js +19 -0
- package/lib/function/string/format.js +2 -2
- package/lib/function/utils/typeof.js +13 -13
- package/lib/index.js +5 -1
- package/lib/type/bignumber/BigNumber.js +6 -2
- package/lib/type/matrix/utils/algorithm13.js +0 -2
- package/lib/type/unit/Unit.js +2 -2
- package/lib/utils/array.js +27 -19
- package/lib/utils/bignumber/formatter.js +3 -2
- package/lib/utils/number.js +15 -10
- package/lib/version.js +1 -1
- package/package.json +13 -8
- package/src/constants.js +3 -1
- package/src/core/function/import.js +15 -2
- package/src/core/typed.js +1 -1
- package/src/expression/node/FunctionNode.js +3 -4
- package/src/expression/parse.js +432 -470
- package/src/function/algebra/decomposition/qr.js +1 -1
- package/src/function/algebra/rationalize.js +41 -43
- package/src/function/algebra/simplify/resolve.js +1 -1
- package/src/function/algebra/simplify/simplifyCore.js +3 -3
- package/src/function/algebra/simplify/util.js +1 -1
- package/src/function/algebra/simplify.js +5 -0
- package/src/function/combinatorics/stirlingS2.js +1 -1
- package/src/function/probability/combinations.js +10 -8
- package/src/function/probability/gamma.js +5 -13
- package/src/function/probability/permutations.js +2 -11
- package/src/function/probability/product.js +17 -0
- package/src/function/string/format.js +2 -2
- package/src/function/utils/typeof.js +13 -13
- package/src/index.js +5 -1
- package/src/type/bignumber/BigNumber.js +2 -1
- package/src/type/matrix/utils/algorithm13.js +0 -2
- package/src/type/unit/Unit.js +2 -2
- package/src/utils/array.js +31 -23
- package/src/utils/bignumber/formatter.js +3 -2
- package/src/utils/number.js +15 -10
- package/src/version.js +1 -1
package/lib/utils/number.js
CHANGED
@@ -75,8 +75,9 @@ exports.sign = Math.sign || function (x) {
|
|
75
75
|
* For example '123.4' and '1.4e7'.
|
76
76
|
* {number} precision A number between 0 and 16 to round
|
77
77
|
* the digits of the number.
|
78
|
-
* In case of notations 'exponential'
|
79
|
-
* '
|
78
|
+
* In case of notations 'exponential',
|
79
|
+
* 'engineering', and 'auto',
|
80
|
+
* `precision` defines the total
|
80
81
|
* number of significant digits returned.
|
81
82
|
* In case of notation 'fixed',
|
82
83
|
* `precision` defines the number of
|
@@ -236,8 +237,7 @@ exports.splitNumber = function (value) {
|
|
236
237
|
/**
|
237
238
|
* Format a number in engineering notation. Like '1.23e+6', '2.3e+0', '3.500e-3'
|
238
239
|
* @param {number | string} value
|
239
|
-
* @param {number} [precision
|
240
|
-
* decimal point. Zero by default.
|
240
|
+
* @param {number} [precision] Optional number of significant figures to return.
|
241
241
|
*/
|
242
242
|
exports.toEngineering = function (value, precision) {
|
243
243
|
if (isNaN(value) || !isFinite(value)) {
|
@@ -252,11 +252,16 @@ exports.toEngineering = function (value, precision) {
|
|
252
252
|
// find nearest lower multiple of 3 for exponent
|
253
253
|
var newExp = e % 3 === 0 ? e : e < 0 ? e - 3 - e % 3 : e - e % 3;
|
254
254
|
|
255
|
-
|
256
|
-
|
255
|
+
if (exports.isNumber(precision)) {
|
256
|
+
// add zeroes to give correct sig figs
|
257
|
+
if (precision > c.length) c = c.concat(zeros(precision - c.length));
|
258
|
+
} else {
|
259
|
+
// concatenate coefficients with necessary zeros
|
260
|
+
var significandsDiff = e >= 0 ? e : Math.abs(newExp);
|
257
261
|
|
258
|
-
|
259
|
-
|
262
|
+
// add zeros if necessary (for ex: 1e+8)
|
263
|
+
if (c.length - 1 < significandsDiff) c = c.concat(zeros(significandsDiff - (c.length - 1)));
|
264
|
+
}
|
260
265
|
|
261
266
|
// find difference in exponents
|
262
267
|
var expDiff = Math.abs(e - newExp);
|
@@ -266,10 +271,10 @@ exports.toEngineering = function (value, precision) {
|
|
266
271
|
// push decimal index over by expDiff times
|
267
272
|
while (--expDiff >= 0) {
|
268
273
|
decimalIdx++;
|
269
|
-
} // if all coefficient values are zero after the decimal point, don't add a decimal value.
|
274
|
+
} // if all coefficient values are zero after the decimal point and precision is unset, don't add a decimal value.
|
270
275
|
// otherwise concat with the rest of the coefficients
|
271
276
|
var decimals = c.slice(decimalIdx).join('');
|
272
|
-
var decimalVal = decimals.match(/[1-9]/) ? '.' + decimals : '';
|
277
|
+
var decimalVal = exports.isNumber(precision) && decimals.length || decimals.match(/[1-9]/) ? '.' + decimals : '';
|
273
278
|
|
274
279
|
var str = c.slice(0, decimalIdx).join('') + decimalVal + 'e' + (e >= 0 ? '+' : '') + newExp.toString();
|
275
280
|
return rounded.sign + str;
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mathjs",
|
3
|
-
"version": "5.0.
|
3
|
+
"version": "5.0.4",
|
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": [
|
@@ -8,9 +8,12 @@
|
|
8
8
|
"Alexander Beyn (https://github.com/AlexanderBeyn)",
|
9
9
|
"Andy Pan (https://github.com/andy0130tw)",
|
10
10
|
"Bart Kiers (https://github.com/bkiers)",
|
11
|
+
"Ben Weinshel (https://github.com/weinshel)",
|
11
12
|
"Brett Jurgens (https://github.com/brettjurgens)",
|
12
13
|
"Bryan Cuccioli (https://github.com/bcuccioli)",
|
14
|
+
"Chris Chudzicki (https://github.com/ChristopherChudzicki)",
|
13
15
|
"Dakota Blair (https://github.com/dakotablair)",
|
16
|
+
"Daniel Kostro (https://github.com/stropitek)",
|
14
17
|
"Daniel Levin (https://github.com/daniel-levin)",
|
15
18
|
"David Simons (https://github.com/SwamWithTurtles)",
|
16
19
|
"denisx (https://github.com/denisx)",
|
@@ -24,8 +27,10 @@
|
|
24
27
|
"Favian Contreras (https://github.com/BigFav)",
|
25
28
|
"Finn Pauls (https://github.com/finnp)",
|
26
29
|
"Ganga Christopher (https://github.com/gangachris)",
|
30
|
+
"Gary Passero (https://github.com/gap777)",
|
27
31
|
"Harry Sarson (https://github.com/HarrySarson)",
|
28
32
|
"Holman Gao (https://github.com/golmansax)",
|
33
|
+
"Honybar (https://github.com/honeybar)",
|
29
34
|
"Guillermo Indalecio Fernández (https://github.com/guillermobox)",
|
30
35
|
"Gulfaraz (https://github.com/gulfaraz)",
|
31
36
|
"hamadu (https://github.com/hamadu)",
|
@@ -96,29 +101,29 @@
|
|
96
101
|
"unit"
|
97
102
|
],
|
98
103
|
"dependencies": {
|
99
|
-
"complex.js": "2.0.
|
104
|
+
"complex.js": "2.0.11",
|
100
105
|
"decimal.js": "10.0.1",
|
101
106
|
"escape-latex": "1.1.0",
|
102
107
|
"fraction.js": "4.0.8",
|
103
108
|
"javascript-natural-sort": "0.7.1",
|
104
109
|
"seed-random": "2.2.0",
|
105
110
|
"tiny-emitter": "2.0.2",
|
106
|
-
"typed-function": "1.0.
|
111
|
+
"typed-function": "1.0.4"
|
107
112
|
},
|
108
113
|
"devDependencies": {
|
109
114
|
"babel-core": "6.26.3",
|
110
|
-
"babel-loader": "7.1.
|
115
|
+
"babel-loader": "7.1.5",
|
111
116
|
"babel-plugin-transform-object-assign": "6.22.0",
|
112
117
|
"babel-preset-env": "1.7.0",
|
113
118
|
"benchmark": "2.1.4",
|
114
|
-
"expr-eval": "1.2.
|
119
|
+
"expr-eval": "1.2.2",
|
115
120
|
"glob": "7.1.2",
|
116
121
|
"gulp": "3.9.1",
|
117
122
|
"gulp-babel": "7.0.1",
|
118
123
|
"gulp-util": "3.0.8",
|
119
124
|
"istanbul": "0.4.5",
|
120
125
|
"jsep": "0.3.4",
|
121
|
-
"karma": "2.0.
|
126
|
+
"karma": "2.0.4",
|
122
127
|
"karma-browserstack-launcher": "1.3.0",
|
123
128
|
"karma-firefox-launcher": "1.1.0",
|
124
129
|
"karma-mocha": "1.3.0",
|
@@ -139,9 +144,9 @@
|
|
139
144
|
"standard": "11.0.1",
|
140
145
|
"sylvester": "0.0.21",
|
141
146
|
"tar": "4.4.4",
|
142
|
-
"uglify-js": "3.4.
|
147
|
+
"uglify-js": "3.4.3",
|
143
148
|
"underscore": "1.9.1",
|
144
|
-
"webpack": "4.
|
149
|
+
"webpack": "4.15.1",
|
145
150
|
"zeros": "1.0.0"
|
146
151
|
},
|
147
152
|
"main": "./index",
|
package/src/constants.js
CHANGED
@@ -56,7 +56,9 @@ function factory (type, config, load, typed, math) {
|
|
56
56
|
}
|
57
57
|
|
58
58
|
// complex i
|
59
|
-
|
59
|
+
if (type.Complex) {
|
60
|
+
setConstant(math, 'i', type.Complex.I)
|
61
|
+
}
|
60
62
|
|
61
63
|
// meta information
|
62
64
|
setConstant(math, 'version', require('./version'))
|
@@ -151,6 +151,15 @@ function factory (type, config, load, typed, math) {
|
|
151
151
|
}
|
152
152
|
}
|
153
153
|
|
154
|
+
function _deleteTransform (name) {
|
155
|
+
delete math.expression.transform[name]
|
156
|
+
if (allowedInExpressions(name)) {
|
157
|
+
math.expression.mathWithTransform[name] = math[name]
|
158
|
+
} else {
|
159
|
+
delete math.expression.mathWithTransform[name]
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
154
163
|
/**
|
155
164
|
* Create a wrapper a round an function which converts the arguments
|
156
165
|
* to their primitive values (like convert a Matrix to Array)
|
@@ -218,7 +227,9 @@ function factory (type, config, load, typed, math) {
|
|
218
227
|
if (factory.lazy !== false) {
|
219
228
|
lazy(namespace, name, resolver)
|
220
229
|
|
221
|
-
if (
|
230
|
+
if (existingTransform) {
|
231
|
+
_deleteTransform(name)
|
232
|
+
} else {
|
222
233
|
if (factory.path === 'expression.transform' || factoryAllowedInExpressions(factory)) {
|
223
234
|
lazy(math.expression.mathWithTransform, name, resolver)
|
224
235
|
}
|
@@ -226,7 +237,9 @@ function factory (type, config, load, typed, math) {
|
|
226
237
|
} else {
|
227
238
|
namespace[name] = resolver()
|
228
239
|
|
229
|
-
if (
|
240
|
+
if (existingTransform) {
|
241
|
+
_deleteTransform(name)
|
242
|
+
} else {
|
230
243
|
if (factory.path === 'expression.transform' || factoryAllowedInExpressions(factory)) {
|
231
244
|
math.expression.mathWithTransform[name] = resolver()
|
232
245
|
}
|
package/src/core/typed.js
CHANGED
@@ -120,7 +120,7 @@ exports.create = function create (type) {
|
|
120
120
|
{ name: 'RangeNode', test: type.isRangeNode },
|
121
121
|
{ name: 'Node', test: type.isNode },
|
122
122
|
|
123
|
-
{ name: 'Object', test: type.isObject } // order 'Object' last, it
|
123
|
+
{ name: 'Object', test: type.isObject } // order 'Object' last, it matches on other classes too
|
124
124
|
]
|
125
125
|
|
126
126
|
// TODO: add conversion from BigNumber to number?
|
@@ -82,7 +82,6 @@ function factory (type, config, load, typed, math) {
|
|
82
82
|
const evalArgs = map(this.args, function (arg) {
|
83
83
|
return arg._compile(math, argNames)
|
84
84
|
})
|
85
|
-
// const jsScope = compileScope(defs, args) // TODO: jsScope
|
86
85
|
|
87
86
|
if (type.isSymbolNode(this.fn)) {
|
88
87
|
// we can statically determine whether the function has an rawArgs property
|
@@ -95,7 +94,7 @@ function factory (type, config, load, typed, math) {
|
|
95
94
|
// "raw" evaluation
|
96
95
|
const rawArgs = this.args
|
97
96
|
return function evalFunctionNode (scope, args, context) {
|
98
|
-
return (name in scope ? getSafeProperty(scope, name) : fn)(rawArgs, math, scope)
|
97
|
+
return (name in scope ? getSafeProperty(scope, name) : fn)(rawArgs, math, Object.assign({}, scope, args))
|
99
98
|
}
|
100
99
|
} else {
|
101
100
|
// "regular" evaluation
|
@@ -132,7 +131,7 @@ function factory (type, config, load, typed, math) {
|
|
132
131
|
const isRaw = object[prop] && object[prop].rawArgs
|
133
132
|
|
134
133
|
return isRaw
|
135
|
-
? object[prop](rawArgs, math, scope) // "raw" evaluation
|
134
|
+
? object[prop](rawArgs, math, Object.assign({}, scope, args)) // "raw" evaluation
|
136
135
|
: object[prop].apply(object, map(evalArgs, function (evalArg) { // "regular" evaluation
|
137
136
|
return evalArg(scope, args, context)
|
138
137
|
}))
|
@@ -147,7 +146,7 @@ function factory (type, config, load, typed, math) {
|
|
147
146
|
const isRaw = fn && fn.rawArgs
|
148
147
|
|
149
148
|
return isRaw
|
150
|
-
? fn(rawArgs, math, scope) // "raw" evaluation
|
149
|
+
? fn(rawArgs, math, Object.assign({}, scope, args)) // "raw" evaluation
|
151
150
|
: fn.apply(fn, map(evalArgs, function (evalArg) { // "regular" evaluation
|
152
151
|
return evalArg(scope, args, context)
|
153
152
|
}))
|