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.

Files changed (71) hide show
  1. package/HISTORY.md +48 -1
  2. package/README.md +2 -1
  3. package/dist/math.js +20114 -20090
  4. package/dist/math.min.js +7 -7
  5. package/dist/math.min.map +1 -1
  6. package/docs/core/configuration.md +1 -1
  7. package/docs/datatypes/numbers.md +1 -1
  8. package/docs/datatypes/units.md +1 -1
  9. package/docs/expressions/algebra.md +25 -1
  10. package/docs/getting_started.md +2 -2
  11. package/docs/reference/functions/format.md +2 -2
  12. package/docs/reference/functions/qr.md +2 -1
  13. package/docs/reference/functions/rationalize.md +13 -10
  14. package/docs/reference/functions/stirlingS2.md +1 -1
  15. package/docs/reference/functions/typeof.md +13 -13
  16. package/examples/advanced/add_new_datatypes/MyType.js +0 -10
  17. package/examples/advanced/add_new_datatypes/index.js +2 -6
  18. package/examples/browser/rocket_trajectory_optimization.html +2 -2
  19. package/lib/constants.js +3 -1
  20. package/lib/core/function/import.js +15 -2
  21. package/lib/core/typed.js +1 -1
  22. package/lib/expression/node/FunctionNode.js +5 -4
  23. package/lib/expression/parse.js +429 -466
  24. package/lib/function/algebra/decomposition/qr.js +1 -1
  25. package/lib/function/algebra/rationalize.js +41 -45
  26. package/lib/function/algebra/simplify/resolve.js +1 -1
  27. package/lib/function/algebra/simplify/simplifyCore.js +3 -3
  28. package/lib/function/algebra/simplify/util.js +1 -1
  29. package/lib/function/algebra/simplify.js +5 -0
  30. package/lib/function/combinatorics/stirlingS2.js +1 -1
  31. package/lib/function/probability/combinations.js +11 -10
  32. package/lib/function/probability/gamma.js +5 -13
  33. package/lib/function/probability/permutations.js +2 -12
  34. package/lib/function/probability/product.js +19 -0
  35. package/lib/function/string/format.js +2 -2
  36. package/lib/function/utils/typeof.js +13 -13
  37. package/lib/index.js +5 -1
  38. package/lib/type/bignumber/BigNumber.js +6 -2
  39. package/lib/type/matrix/utils/algorithm13.js +0 -2
  40. package/lib/type/unit/Unit.js +2 -2
  41. package/lib/utils/array.js +27 -19
  42. package/lib/utils/bignumber/formatter.js +3 -2
  43. package/lib/utils/number.js +15 -10
  44. package/lib/version.js +1 -1
  45. package/package.json +13 -8
  46. package/src/constants.js +3 -1
  47. package/src/core/function/import.js +15 -2
  48. package/src/core/typed.js +1 -1
  49. package/src/expression/node/FunctionNode.js +3 -4
  50. package/src/expression/parse.js +432 -470
  51. package/src/function/algebra/decomposition/qr.js +1 -1
  52. package/src/function/algebra/rationalize.js +41 -43
  53. package/src/function/algebra/simplify/resolve.js +1 -1
  54. package/src/function/algebra/simplify/simplifyCore.js +3 -3
  55. package/src/function/algebra/simplify/util.js +1 -1
  56. package/src/function/algebra/simplify.js +5 -0
  57. package/src/function/combinatorics/stirlingS2.js +1 -1
  58. package/src/function/probability/combinations.js +10 -8
  59. package/src/function/probability/gamma.js +5 -13
  60. package/src/function/probability/permutations.js +2 -11
  61. package/src/function/probability/product.js +17 -0
  62. package/src/function/string/format.js +2 -2
  63. package/src/function/utils/typeof.js +13 -13
  64. package/src/index.js +5 -1
  65. package/src/type/bignumber/BigNumber.js +2 -1
  66. package/src/type/matrix/utils/algorithm13.js +0 -2
  67. package/src/type/unit/Unit.js +2 -2
  68. package/src/utils/array.js +31 -23
  69. package/src/utils/bignumber/formatter.js +3 -2
  70. package/src/utils/number.js +15 -10
  71. package/src/version.js +1 -1
@@ -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' and
81
- * 'auto', `precision` defines the total
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=0] Optional number of decimals after the
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
- // concatenate coefficients with necessary zeros
265
- const significandsDiff = e >= 0 ? e : Math.abs(newExp)
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
- // add zeros if necessary (for ex: 1e+8)
268
- if (c.length - 1 < significandsDiff) c = c.concat(zeros(significandsDiff - (c.length - 1)))
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
@@ -1,3 +1,3 @@
1
- module.exports = '5.0.0'
1
+ module.exports = '5.0.4'
2
2
  // Note: This file is automatically generated when building math.js.
3
3
  // Changes made in this file will be overwritten.