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/src/utils/number.js
CHANGED
@@ -77,8 +77,9 @@ exports.sign = Math.sign || function (x) {
|
|
77
77
|
* For example '123.4' and '1.4e7'.
|
78
78
|
* {number} precision A number between 0 and 16 to round
|
79
79
|
* the digits of the number.
|
80
|
-
* In case of notations 'exponential'
|
81
|
-
* '
|
80
|
+
* In case of notations 'exponential',
|
81
|
+
* 'engineering', and 'auto',
|
82
|
+
* `precision` defines the total
|
82
83
|
* number of significant digits returned.
|
83
84
|
* In case of notation 'fixed',
|
84
85
|
* `precision` defines the number of
|
@@ -245,8 +246,7 @@ exports.splitNumber = function (value) {
|
|
245
246
|
/**
|
246
247
|
* Format a number in engineering notation. Like '1.23e+6', '2.3e+0', '3.500e-3'
|
247
248
|
* @param {number | string} value
|
248
|
-
* @param {number} [precision
|
249
|
-
* decimal point. Zero by default.
|
249
|
+
* @param {number} [precision] Optional number of significant figures to return.
|
250
250
|
*/
|
251
251
|
exports.toEngineering = function (value, precision) {
|
252
252
|
if (isNaN(value) || !isFinite(value)) {
|
@@ -261,11 +261,16 @@ exports.toEngineering = function (value, precision) {
|
|
261
261
|
// find nearest lower multiple of 3 for exponent
|
262
262
|
const newExp = e % 3 === 0 ? e : (e < 0 ? (e - 3) - (e % 3) : e - (e % 3))
|
263
263
|
|
264
|
-
|
265
|
-
|
264
|
+
if (exports.isNumber(precision)) {
|
265
|
+
// add zeroes to give correct sig figs
|
266
|
+
if (precision > c.length) c = c.concat(zeros(precision - c.length))
|
267
|
+
} else {
|
268
|
+
// concatenate coefficients with necessary zeros
|
269
|
+
const significandsDiff = e >= 0 ? e : Math.abs(newExp)
|
266
270
|
|
267
|
-
|
268
|
-
|
271
|
+
// add zeros if necessary (for ex: 1e+8)
|
272
|
+
if (c.length - 1 < significandsDiff) c = c.concat(zeros(significandsDiff - (c.length - 1)))
|
273
|
+
}
|
269
274
|
|
270
275
|
// find difference in exponents
|
271
276
|
let expDiff = Math.abs(e - newExp)
|
@@ -275,10 +280,10 @@ exports.toEngineering = function (value, precision) {
|
|
275
280
|
// push decimal index over by expDiff times
|
276
281
|
while (--expDiff >= 0) decimalIdx++
|
277
282
|
|
278
|
-
// if all coefficient values are zero after the decimal point, don't add a decimal value.
|
283
|
+
// if all coefficient values are zero after the decimal point and precision is unset, don't add a decimal value.
|
279
284
|
// otherwise concat with the rest of the coefficients
|
280
285
|
const decimals = c.slice(decimalIdx).join('')
|
281
|
-
const decimalVal = decimals.match(/[1-9]/) ? ('.' + decimals) : ''
|
286
|
+
const decimalVal = ((exports.isNumber(precision) && decimals.length) || decimals.match(/[1-9]/)) ? ('.' + decimals) : ''
|
282
287
|
|
283
288
|
const str = c.slice(0, decimalIdx).join('') +
|
284
289
|
decimalVal +
|
package/src/version.js
CHANGED