mathjs 11.7.0 → 11.8.1

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.
Files changed (88) hide show
  1. package/HISTORY.md +26 -0
  2. package/README.md +0 -26
  3. package/lib/browser/math.js +1 -1
  4. package/lib/browser/math.js.LICENSE.txt +2 -2
  5. package/lib/browser/math.js.map +1 -1
  6. package/lib/cjs/core/function/typed.js +1 -1
  7. package/lib/cjs/entry/dependenciesAny/dependenciesDistance.generated.js +2 -2
  8. package/lib/cjs/entry/pureFunctionsAny.generated.js +2 -2
  9. package/lib/cjs/expression/Parser.js +1 -1
  10. package/lib/cjs/expression/function/parser.js +1 -1
  11. package/lib/cjs/expression/node/FunctionAssignmentNode.js +1 -1
  12. package/lib/cjs/expression/node/OperatorNode.js +1 -3
  13. package/lib/cjs/expression/operators.js +19 -4
  14. package/lib/cjs/expression/transform/filter.transform.js +4 -13
  15. package/lib/cjs/expression/transform/forEach.transform.js +3 -12
  16. package/lib/cjs/expression/transform/map.transform.js +4 -13
  17. package/lib/cjs/factoriesNumber.js +18 -0
  18. package/lib/cjs/function/algebra/derivative.js +2 -2
  19. package/lib/cjs/function/algebra/leafCount.js +1 -1
  20. package/lib/cjs/function/algebra/polynomialRoot.js +1 -1
  21. package/lib/cjs/function/algebra/rationalize.js +5 -7
  22. package/lib/cjs/function/algebra/resolve.js +1 -1
  23. package/lib/cjs/function/algebra/simplify.js +7 -7
  24. package/lib/cjs/function/algebra/simplifyConstant.js +3 -3
  25. package/lib/cjs/function/algebra/simplifyCore.js +2 -2
  26. package/lib/cjs/function/algebra/sparse/csAmd.js +1 -3
  27. package/lib/cjs/function/algebra/sparse/csLeaf.js +1 -3
  28. package/lib/cjs/function/algebra/symbolicEqual.js +8 -8
  29. package/lib/cjs/function/geometry/distance.js +31 -29
  30. package/lib/cjs/function/matrix/eigs/complexEigs.js +3 -3
  31. package/lib/cjs/function/matrix/filter.js +2 -11
  32. package/lib/cjs/function/matrix/forEach.js +3 -12
  33. package/lib/cjs/function/matrix/map.js +6 -38
  34. package/lib/cjs/function/matrix/matrixFromColumns.js +1 -1
  35. package/lib/cjs/function/matrix/matrixFromRows.js +1 -1
  36. package/lib/cjs/function/matrix/sqrtm.js +1 -1
  37. package/lib/cjs/header.js +2 -2
  38. package/lib/cjs/type/bignumber/function/bignumber.js +7 -0
  39. package/lib/cjs/type/fraction/function/fraction.js +8 -1
  40. package/lib/cjs/type/matrix/DenseMatrix.js +41 -45
  41. package/lib/cjs/type/matrix/SparseMatrix.js +39 -41
  42. package/lib/cjs/type/number.js +7 -3
  43. package/lib/cjs/type/unit/Unit.js +2 -0
  44. package/lib/cjs/type/unit/function/splitUnit.js +1 -1
  45. package/lib/cjs/utils/applyCallback.js +73 -0
  46. package/lib/cjs/utils/bignumber/formatter.js +4 -3
  47. package/lib/cjs/utils/lruQueue.js +2 -6
  48. package/lib/cjs/utils/map.js +1 -1
  49. package/lib/cjs/utils/snapshot.js +7 -1
  50. package/lib/cjs/version.js +1 -1
  51. package/lib/esm/core/function/typed.js +1 -1
  52. package/lib/esm/entry/dependenciesAny/dependenciesDistance.generated.js +2 -2
  53. package/lib/esm/entry/pureFunctionsAny.generated.js +2 -2
  54. package/lib/esm/expression/Parser.js +1 -1
  55. package/lib/esm/expression/function/parser.js +1 -1
  56. package/lib/esm/expression/node/OperatorNode.js +1 -3
  57. package/lib/esm/expression/operators.js +1 -3
  58. package/lib/esm/expression/transform/filter.transform.js +4 -13
  59. package/lib/esm/expression/transform/forEach.transform.js +3 -12
  60. package/lib/esm/expression/transform/map.transform.js +4 -13
  61. package/lib/esm/function/algebra/derivative.js +2 -2
  62. package/lib/esm/function/algebra/leafCount.js +1 -1
  63. package/lib/esm/function/algebra/polynomialRoot.js +1 -1
  64. package/lib/esm/function/algebra/rationalize.js +5 -7
  65. package/lib/esm/function/algebra/resolve.js +1 -1
  66. package/lib/esm/function/algebra/simplify.js +7 -7
  67. package/lib/esm/function/algebra/simplifyConstant.js +2 -2
  68. package/lib/esm/function/algebra/simplifyCore.js +2 -2
  69. package/lib/esm/function/algebra/sparse/csAmd.js +1 -3
  70. package/lib/esm/function/algebra/sparse/csLeaf.js +1 -3
  71. package/lib/esm/function/algebra/symbolicEqual.js +8 -8
  72. package/lib/esm/function/geometry/distance.js +31 -29
  73. package/lib/esm/function/matrix/eigs/complexEigs.js +2 -2
  74. package/lib/esm/function/matrix/filter.js +2 -11
  75. package/lib/esm/function/matrix/forEach.js +3 -12
  76. package/lib/esm/function/matrix/map.js +6 -38
  77. package/lib/esm/function/matrix/sqrtm.js +1 -1
  78. package/lib/esm/type/bignumber/function/bignumber.js +5 -0
  79. package/lib/esm/type/fraction/function/fraction.js +6 -1
  80. package/lib/esm/type/number.js +5 -3
  81. package/lib/esm/type/unit/Unit.js +2 -0
  82. package/lib/esm/type/unit/function/splitUnit.js +1 -1
  83. package/lib/esm/utils/applyCallback.js +67 -0
  84. package/lib/esm/utils/bignumber/formatter.js +4 -3
  85. package/lib/esm/utils/lruQueue.js +2 -6
  86. package/lib/esm/version.js +1 -1
  87. package/package.json +21 -21
  88. package/types/index.d.ts +16 -16
@@ -1,7 +1,7 @@
1
1
  import { isBigNumber } from '../../utils/is.js';
2
2
  import { factory } from '../../utils/factory.js';
3
3
  var name = 'distance';
4
- var dependencies = ['typed', 'addScalar', 'subtract', 'divideScalar', 'multiplyScalar', 'unaryMinus', 'sqrt', 'abs'];
4
+ var dependencies = ['typed', 'addScalar', 'subtract', 'divideScalar', 'multiplyScalar', 'deepEqual', 'sqrt', 'abs'];
5
5
  export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
6
6
  var {
7
7
  typed,
@@ -9,7 +9,7 @@ export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
9
9
  subtract,
10
10
  multiplyScalar,
11
11
  divideScalar,
12
- unaryMinus,
12
+ deepEqual,
13
13
  sqrt,
14
14
  abs
15
15
  } = _ref;
@@ -23,21 +23,19 @@ export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
23
23
  * For parametric equation of a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b, c)
24
24
  *
25
25
  * Syntax:
26
- * math.distance([x1, y1], [x2, y2])
27
- * math.distance({pointOneX: 4, pointOneY: 5}, {pointTwoX: 2, pointTwoY: 7})
28
- * math.distance([x1, y1, z1], [x2, y2, z2])
29
- * math.distance({pointOneX: 4, pointOneY: 5, pointOneZ: 8}, {pointTwoX: 2, pointTwoY: 7, pointTwoZ: 9})
30
- * math.distance([x1, y1, ... , N1], [x2, y2, ... , N2])
31
- * math.distance([[A], [B], [C]...])
32
- * math.distance([x1, y1], [LinePtX1, LinePtY1], [LinePtX2, LinePtY2])
33
- * math.distance({pointX: 1, pointY: 4}, {lineOnePtX: 6, lineOnePtY: 3}, {lineTwoPtX: 2, lineTwoPtY: 8})
34
- * math.distance([x1, y1, z1], [LinePtX1, LinePtY1, LinePtZ1], [LinePtX2, LinePtY2, LinePtZ2])
35
- * math.distance({pointX: 1, pointY: 4, pointZ: 7}, {lineOnePtX: 6, lineOnePtY: 3, lineOnePtZ: 4}, {lineTwoPtX: 2, lineTwoPtY: 8, lineTwoPtZ: 5})
36
- * math.distance([x1, y1], [xCoeffLine, yCoeffLine, constant])
37
- * math.distance({pointX: 10, pointY: 10}, {xCoeffLine: 8, yCoeffLine: 1, constant: 3})
38
- * math.distance([x1, y1, z1], [x0, y0, z0, a-tCoeff, b-tCoeff, c-tCoeff]) // point and parametric equation of 3D line
39
- * math.distance([x, y, z], [x0, y0, z0, a, b, c])
40
- * math.distance({pointX: 2, pointY: 5, pointZ: 9}, {x0: 4, y0: 6, z0: 3, a: 4, b: 2, c: 0})
26
+ *
27
+ * math.distance([x1,y1], [x2,y2])
28
+ * math.distance({pointOneX, pointOneY}, {pointTwoX, pointTwoY})
29
+ * math.distance([x1,y1,z1], [x2,y2,z2])
30
+ * math.distance({pointOneX, pointOneY, pointOneZ}, {pointTwoX, pointTwoY, pointTwoZ})
31
+ * math.distance([x1,y1,z1,a1], [x2,y2,z2,a2])
32
+ * math.distance([[x1,y1], [x2,y2], [x3,y3]])
33
+ * math.distance([[x1,y1,z1], [x2,y2,z2], [x3,y3,z3]])
34
+ * math.distance([pointX,pointY], [a,b,c])
35
+ * math.distance([pointX,pointY], [lineOnePtX,lineOnePtY], [lineTwoPtX,lineTwoPtY])
36
+ * math.distance({pointX, pointY}, {lineOnePtX, lineOnePtY}, {lineTwoPtX, lineTwoPtY})
37
+ * math.distance([pointX,pointY,pointZ], [x0, y0, z0, a, b, c])
38
+ * math.distance({pointX, pointY, pointZ}, {x0, y0, z0, a, b, c})
41
39
  *
42
40
  * Examples:
43
41
  * math.distance([0,0], [4,4]) // Returns 5.656854249492381
@@ -52,11 +50,11 @@ export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
52
50
  * math.distance([[1, 2], [1, 2], [1, 3]]) // Returns [0, 1, 1]
53
51
  * math.distance([[1,2,4], [1,2,6], [8,1,3]]) // Returns [2, 7.14142842854285, 7.681145747868608]
54
52
  * math.distance([10, 10], [8, 1, 3]) // Returns 11.535230316796387
55
- * math.distance([10, 10], [2, 3], [-8, 0]) // Returns 8.759953130362847
53
+ * math.distance([0, 0], [3, 0], [0, 4]) // Returns 2.4
56
54
  * math.distance(
57
- * {pointX: 1, pointY: 4},
58
- * {lineOnePtX: 6, lineOnePtY: 3},
59
- * {lineTwoPtX: 2, lineTwoPtY: 8}) // Returns 2.720549372624744
55
+ * {pointX: 0, pointY: 0},
56
+ * {lineOnePtX: 3, lineOnePtY: 0},
57
+ * {lineTwoPtX: 0, lineTwoPtY: 4}) // Returns 2.4
60
58
  * math.distance([2, 3, 1], [1, 1, 2, 5, 0, 1]) // Returns 2.3204774044612857
61
59
  * math.distance(
62
60
  * {pointX: 2, pointY: 3, pointZ: 1},
@@ -79,10 +77,12 @@ export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
79
77
  if (!_2d(z)) {
80
78
  throw new TypeError('Array with 2 numbers or BigNumbers expected for third argument');
81
79
  }
82
- var m = divideScalar(subtract(z[1], z[0]), subtract(y[1], y[0]));
83
- var xCoeff = multiplyScalar(multiplyScalar(m, m), y[0]);
84
- var yCoeff = unaryMinus(multiplyScalar(m, y[0]));
85
- var constant = x[1];
80
+ if (deepEqual(y, z)) {
81
+ throw new TypeError('LinePoint1 should not be same with LinePoint2');
82
+ }
83
+ var xCoeff = subtract(z[1], y[1]);
84
+ var yCoeff = subtract(y[0], z[0]);
85
+ var constant = subtract(multiplyScalar(z[0], y[1]), multiplyScalar(y[0], z[1]));
86
86
  return _distancePointLine2D(x[0], x[1], xCoeff, yCoeff, constant);
87
87
  } else {
88
88
  throw new TypeError('Invalid Arguments: Try again');
@@ -99,11 +99,13 @@ export var createDistance = /* #__PURE__ */factory(name, dependencies, _ref => {
99
99
  if (!_2d(z)) {
100
100
  throw new TypeError('Values of lineTwoPtX and lineTwoPtY should be numbers or BigNumbers');
101
101
  }
102
+ if (deepEqual(_objectToArray(y), _objectToArray(z))) {
103
+ throw new TypeError('LinePoint1 should not be same with LinePoint2');
104
+ }
102
105
  if ('pointX' in x && 'pointY' in x && 'lineOnePtX' in y && 'lineOnePtY' in y && 'lineTwoPtX' in z && 'lineTwoPtY' in z) {
103
- var m = divideScalar(subtract(z.lineTwoPtY, z.lineTwoPtX), subtract(y.lineOnePtY, y.lineOnePtX));
104
- var xCoeff = multiplyScalar(multiplyScalar(m, m), y.lineOnePtX);
105
- var yCoeff = unaryMinus(multiplyScalar(m, y.lineOnePtX));
106
- var constant = x.pointX;
106
+ var xCoeff = subtract(z.lineTwoPtY, y.lineOnePtY);
107
+ var yCoeff = subtract(y.lineOnePtX, z.lineTwoPtX);
108
+ var constant = subtract(multiplyScalar(z.lineTwoPtX, y.lineOnePtY), multiplyScalar(y.lineOnePtX, z.lineTwoPtY));
107
109
  return _distancePointLine2D(x.pointX, x.pointY, xCoeff, yCoeff, constant);
108
110
  } else {
109
111
  throw new TypeError('Key names do not match');
@@ -435,7 +435,7 @@ export function createComplexEigs(_ref) {
435
435
 
436
436
  // eigenvalues for which usolve failed (due to numerical error)
437
437
  var failedLambdas = [];
438
- var _loop = function _loop(_i4) {
438
+ var _loop = function _loop() {
439
439
  var λ = uniqueValues[_i4];
440
440
  var S = subtract(U, multiply(λ, E)); // the characteristic matrix
441
441
 
@@ -459,7 +459,7 @@ export function createComplexEigs(_ref) {
459
459
  vectors.push(...solutions.map(v => flatten(v)));
460
460
  };
461
461
  for (var _i4 = 0; _i4 < len; _i4++) {
462
- _loop(_i4);
462
+ _loop();
463
463
  }
464
464
  if (failedLambdas.length !== 0) {
465
465
  var err = new Error('Failed to find eigenvectors for the following eigenvalues: ' + failedLambdas.join(', '));
@@ -1,5 +1,5 @@
1
+ import { applyCallback } from '../../utils/applyCallback.js';
1
2
  import { filter, filterRegExp } from '../../utils/array.js';
2
- import { maxArgumentCount } from '../../utils/function.js';
3
3
  import { factory } from '../../utils/factory.js';
4
4
  var name = 'filter';
5
5
  var dependencies = ['typed'];
@@ -56,17 +56,8 @@ export var createFilter = /* #__PURE__ */factory(name, dependencies, _ref => {
56
56
  * @private
57
57
  */
58
58
  function _filterCallback(x, callback) {
59
- // figure out what number of arguments the callback function expects
60
- var args = maxArgumentCount(callback);
61
59
  return filter(x, function (value, index, array) {
62
60
  // invoke the callback function with the right number of arguments
63
- if (args === 1) {
64
- return callback(value);
65
- } else if (args === 2) {
66
- return callback(value, [index]);
67
- } else {
68
- // 3 or -1
69
- return callback(value, [index], array);
70
- }
61
+ return applyCallback(callback, value, [index], array, 'filter');
71
62
  });
72
63
  }
@@ -1,4 +1,4 @@
1
- import { maxArgumentCount } from '../../utils/function.js';
1
+ import { applyCallback } from '../../utils/applyCallback.js';
2
2
  import { forEach as forEachArray } from '../../utils/array.js';
3
3
  import { factory } from '../../utils/factory.js';
4
4
  var name = 'forEach';
@@ -39,14 +39,12 @@ export var createForEach = /* #__PURE__ */factory(name, dependencies, _ref => {
39
39
  });
40
40
 
41
41
  /**
42
- * forEach for a multi dimensional array
42
+ * forEach for a multidimensional array
43
43
  * @param {Array} array
44
44
  * @param {Function} callback
45
45
  * @private
46
46
  */
47
47
  function _forEach(array, callback) {
48
- // figure out what number of arguments the callback function expects
49
- var args = maxArgumentCount(callback);
50
48
  var recurse = function recurse(value, index) {
51
49
  if (Array.isArray(value)) {
52
50
  forEachArray(value, function (child, i) {
@@ -55,14 +53,7 @@ function _forEach(array, callback) {
55
53
  });
56
54
  } else {
57
55
  // invoke the callback function with the right number of arguments
58
- if (args === 1) {
59
- callback(value);
60
- } else if (args === 2) {
61
- callback(value, index);
62
- } else {
63
- // 3 or -1
64
- callback(value, index, array);
65
- }
56
+ return applyCallback(callback, value, index, array, 'forEach');
66
57
  }
67
58
  };
68
59
  recurse(array, []);
@@ -1,4 +1,4 @@
1
- import { maxArgumentCount } from '../../utils/function.js';
1
+ import { applyCallback } from '../../utils/applyCallback.js';
2
2
  import { factory } from '../../utils/factory.js';
3
3
  var name = 'map';
4
4
  var dependencies = ['typed'];
@@ -27,14 +27,9 @@ export var createMap = /* #__PURE__ */factory(name, dependencies, _ref => {
27
27
  * return value * value
28
28
  * }) // returns [1, 4, 9]
29
29
  *
30
- * // The calling convention for the callback can cause subtleties:
31
- * math.map([1, 2, 3], math.format)
32
- * // throws TypeError: map attempted to call 'format(1,[0])' but argument 2 of type Array does not match expected type number or function or Object or string or boolean
33
- * // [This happens because `format` _can_ take a second argument,
34
- * // but its semantics don't match that of the 2nd argument `map` provides]
35
- *
36
- * // To avoid this error, use a function that takes exactly the
37
- * // desired arguments:
30
+ * // The callback is normally called with three arguments:
31
+ * // callback(value, index, Array)
32
+ * // If you want to call with only one argument, use:
38
33
  * math.map([1, 2, 3], x => math.format(x)) // returns ['1', '2', '3']
39
34
  *
40
35
  * See also:
@@ -63,8 +58,6 @@ export var createMap = /* #__PURE__ */factory(name, dependencies, _ref => {
63
58
  * @private
64
59
  */
65
60
  function _map(array, callback) {
66
- // figure out what number of arguments the callback function expects
67
- var args = maxArgumentCount(callback);
68
61
  var recurse = function recurse(value, index) {
69
62
  if (Array.isArray(value)) {
70
63
  return value.map(function (child, i) {
@@ -72,33 +65,8 @@ function _map(array, callback) {
72
65
  return recurse(child, index.concat(i));
73
66
  });
74
67
  } else {
75
- try {
76
- // invoke the callback function with the right number of arguments
77
- if (args === 1) {
78
- return callback(value);
79
- } else if (args === 2) {
80
- return callback(value, index);
81
- } else {
82
- // 3 or -1
83
- return callback(value, index, array);
84
- }
85
- } catch (err) {
86
- // But maybe the arguments still weren't right
87
- if (err instanceof TypeError && 'data' in err && err.data.category === 'wrongType') {
88
- var newmsg = "map attempted to call '".concat(err.data.fn, "(").concat(value);
89
- var indexString = JSON.stringify(index);
90
- if (args === 2) {
91
- newmsg += ',' + indexString;
92
- } else if (args !== 1) {
93
- newmsg += ",".concat(indexString, ",").concat(array);
94
- }
95
- newmsg += ")' but argument ".concat(err.data.index + 1, " of type ");
96
- newmsg += "".concat(err.data.actual, " does not match expected type ");
97
- newmsg += err.data.expected.join(' or ');
98
- throw new TypeError(newmsg);
99
- }
100
- throw err;
101
- }
68
+ // invoke the callback function with the right number of arguments
69
+ return applyCallback(callback, value, index, array, 'map');
102
70
  }
103
71
  };
104
72
  return recurse(array, []);
@@ -55,7 +55,7 @@ export var createSqrtm = /* #__PURE__ */factory(name, dependencies, _ref => {
55
55
  *
56
56
  * Syntax:
57
57
  *
58
- * X = math.sqrtm(A)
58
+ * math.sqrtm(A)
59
59
  *
60
60
  * Examples:
61
61
  *
@@ -63,6 +63,11 @@ export var createBignumber = /* #__PURE__ */factory(name, dependencies, _ref =>
63
63
  // we assume a BigNumber is immutable
64
64
  return x;
65
65
  },
66
+ Unit: typed.referToSelf(self => x => {
67
+ var clone = x.clone();
68
+ clone.value = self(x.value);
69
+ return clone;
70
+ }),
66
71
  Fraction: function Fraction(x) {
67
72
  return new BigNumber(x.n).div(x.d).times(x.s);
68
73
  },
@@ -39,7 +39,7 @@ export var createFraction = /* #__PURE__ */factory(name, dependencies, _ref => {
39
39
  *
40
40
  * bignumber, number, string, unit
41
41
  *
42
- * @param {number | string | Fraction | BigNumber | Array | Matrix} [args]
42
+ * @param {number | string | Fraction | BigNumber | Unit | Array | Matrix} [args]
43
43
  * Arguments specifying the value, or numerator and denominator of
44
44
  * the fraction
45
45
  * @return {Fraction | Array | Matrix} Returns a fraction
@@ -67,6 +67,11 @@ export var createFraction = /* #__PURE__ */factory(name, dependencies, _ref => {
67
67
  return x; // fractions are immutable
68
68
  },
69
69
 
70
+ Unit: typed.referToSelf(self => x => {
71
+ var clone = x.clone();
72
+ clone.value = self(x.value);
73
+ return clone;
74
+ }),
70
75
  Object: function Object(x) {
71
76
  return new Fraction(x);
72
77
  },
@@ -121,9 +121,11 @@ export var createNumber = /* #__PURE__ */factory(name, dependencies, _ref => {
121
121
  Fraction: function Fraction(x) {
122
122
  return x.valueOf();
123
123
  },
124
- Unit: function Unit(x) {
125
- throw new Error('Second argument with valueless unit expected');
126
- },
124
+ Unit: typed.referToSelf(self => x => {
125
+ var clone = x.clone();
126
+ clone.value = self(x.value);
127
+ return clone;
128
+ }),
127
129
  null: function _null(x) {
128
130
  return 0;
129
131
  },
@@ -3260,6 +3260,8 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
3260
3260
  watts: 'watt',
3261
3261
  joules: 'joule',
3262
3262
  amperes: 'ampere',
3263
+ amps: 'ampere',
3264
+ amp: 'ampere',
3263
3265
  coulombs: 'coulomb',
3264
3266
  volts: 'volt',
3265
3267
  ohms: 'ohm',
@@ -10,7 +10,7 @@ export var createSplitUnit = /* #__PURE__ */factory(name, dependencies, _ref =>
10
10
  *
11
11
  * Syntax:
12
12
  *
13
- * splitUnit(unit: Unit, parts: Array.<Unit>)
13
+ * math.splitUnit(unit: Unit, parts: Array.<Unit>)
14
14
  *
15
15
  * Example:
16
16
  *
@@ -0,0 +1,67 @@
1
+ import typed from 'typed-function';
2
+ import { typeOf as _typeOf } from './is.js';
3
+
4
+ /**
5
+ * Invoke a callback for functions like map and filter with a matching number of arguments
6
+ * @param {function} callback
7
+ * @param {any} value
8
+ * @param {number | number[]} index
9
+ * @param {Array} array
10
+ * @param {string} mappingFnName The name of the function that is invoking these callbacks, for example "map" or "filter"
11
+ * @returns {*}
12
+ */
13
+ export function applyCallback(callback, value, index, array, mappingFnName) {
14
+ if (typed.isTypedFunction(callback)) {
15
+ // invoke the typed callback function with the matching number of arguments only
16
+
17
+ var args3 = [value, index, array];
18
+ var signature3 = typed.resolve(callback, args3);
19
+ if (signature3) {
20
+ return tryWithArgs(signature3.implementation, args3);
21
+ }
22
+ var args2 = [value, index];
23
+ var signature2 = typed.resolve(callback, args2);
24
+ if (signature2) {
25
+ return tryWithArgs(signature2.implementation, args2);
26
+ }
27
+ var args1 = [value];
28
+ var signature1 = typed.resolve(callback, args1);
29
+ if (signature1) {
30
+ return tryWithArgs(signature1.implementation, args1);
31
+ }
32
+
33
+ // fallback (will throw an exception)
34
+ return tryWithArgs(callback, args3);
35
+ } else {
36
+ // A regular JavaScript function
37
+ return callback(value, index, array);
38
+ }
39
+
40
+ /**
41
+ * @param {function} signature The selected signature of the typed-function
42
+ * @param {Array} args List with arguments to apply to the selected signature
43
+ * @returns {*} Returns the return value of the invoked signature
44
+ * @throws {TypeError} Throws an error when no matching signature was found
45
+ */
46
+ function tryWithArgs(signature, args) {
47
+ try {
48
+ return signature.apply(signature, args);
49
+ } catch (err) {
50
+ var _err$data;
51
+ // Enrich the error message so the user understands that it took place inside the callback function
52
+ if (err instanceof TypeError && ((_err$data = err.data) === null || _err$data === void 0 ? void 0 : _err$data.category) === 'wrongType') {
53
+ var argsDesc = [];
54
+ argsDesc.push("value: ".concat(_typeOf(value)));
55
+ if (args.length >= 2) {
56
+ argsDesc.push("index: ".concat(_typeOf(index)));
57
+ }
58
+ if (args.length >= 3) {
59
+ argsDesc.push("array: ".concat(_typeOf(array)));
60
+ }
61
+ throw new TypeError("Function ".concat(mappingFnName, " cannot apply callback arguments ") + "".concat(callback.name, "(").concat(argsDesc.join(', '), ") at index ").concat(JSON.stringify(index)));
62
+ } else {
63
+ throw new TypeError("Function ".concat(mappingFnName, " cannot apply callback arguments ") + "to function ".concat(callback.name, ": ").concat(err.message));
64
+ }
65
+ }
66
+ }
67
+ }
@@ -146,7 +146,7 @@ export function format(value, options) {
146
146
  // determine precision from options
147
147
  if (typeof options === 'number') {
148
148
  precision = options;
149
- } else if (options.precision) {
149
+ } else if (options.precision !== undefined) {
150
150
  precision = options.precision;
151
151
  }
152
152
  if (options.wordSize) {
@@ -207,7 +207,7 @@ export function format(value, options) {
207
207
 
208
208
  /**
209
209
  * Format a BigNumber in engineering notation. Like '1.23e+6', '2.3e+0', '3.500e-3'
210
- * @param {BigNumber | string} value
210
+ * @param {BigNumber} value
211
211
  * @param {number} [precision] Optional number of significant figures to return.
212
212
  */
213
213
  export function toEngineering(value, precision) {
@@ -219,7 +219,8 @@ export function toEngineering(value, precision) {
219
219
  var valueWithoutExp = value.mul(Math.pow(10, -newExp));
220
220
  var valueStr = valueWithoutExp.toPrecision(precision);
221
221
  if (valueStr.indexOf('e') !== -1) {
222
- valueStr = valueWithoutExp.toString();
222
+ var BigNumber = value.constructor;
223
+ valueStr = new BigNumber(valueStr).toFixed();
223
224
  }
224
225
  return valueStr + 'e' + (e >= 0 ? '+' : '') + newExp.toString();
225
226
  }
@@ -19,9 +19,7 @@ export function lruQueue(limit) {
19
19
  base = 1;
20
20
  return;
21
21
  }
22
- while (!hasOwnProperty.call(queue, ++base)) {
23
- continue;
24
- }
22
+ while (!hasOwnProperty.call(queue, ++base)) continue;
25
23
  };
26
24
  limit = Math.abs(limit);
27
25
  return {
@@ -39,9 +37,7 @@ export function lruQueue(limit) {
39
37
  }
40
38
  delete queue[oldIndex];
41
39
  if (base !== oldIndex) return undefined;
42
- while (!hasOwnProperty.call(queue, ++base)) {
43
- continue;
44
- }
40
+ while (!hasOwnProperty.call(queue, ++base)) continue;
45
41
  return undefined;
46
42
  },
47
43
  delete: del,
@@ -1,3 +1,3 @@
1
- export var version = '11.7.0';
1
+ export var version = '11.8.1';
2
2
  // Note: This file is automatically generated when building math.js.
3
3
  // Changes made in this file will be overwritten.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mathjs",
3
- "version": "11.7.0",
3
+ "version": "11.8.1",
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
  "homepage": "https://mathjs.org",
@@ -25,7 +25,7 @@
25
25
  "unit"
26
26
  ],
27
27
  "dependencies": {
28
- "@babel/runtime": "^7.21.0",
28
+ "@babel/runtime": "^7.22.5",
29
29
  "complex.js": "^2.1.1",
30
30
  "decimal.js": "^10.4.3",
31
31
  "escape-latex": "^1.2.0",
@@ -36,32 +36,32 @@
36
36
  "typed-function": "^4.1.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@babel/core": "7.21.3",
40
- "@babel/plugin-transform-object-assign": "7.18.6",
41
- "@babel/plugin-transform-runtime": "7.21.0",
42
- "@babel/preset-env": "7.20.2",
43
- "@babel/register": "7.21.0",
39
+ "@babel/core": "7.22.5",
40
+ "@babel/plugin-transform-object-assign": "7.22.5",
41
+ "@babel/plugin-transform-runtime": "7.22.5",
42
+ "@babel/preset-env": "7.22.5",
43
+ "@babel/register": "7.22.5",
44
44
  "@types/assert": "1.5.6",
45
45
  "@types/mocha": "10.0.1",
46
- "@typescript-eslint/eslint-plugin": "5.55.0",
47
- "@typescript-eslint/parser": "5.55.0",
46
+ "@typescript-eslint/eslint-plugin": "5.59.11",
47
+ "@typescript-eslint/parser": "5.59.11",
48
48
  "assert": "2.0.0",
49
49
  "babel-loader": "9.1.2",
50
50
  "benchmark": "2.1.4",
51
- "c8": "7.13.0",
51
+ "c8": "7.14.0",
52
52
  "codecov": "3.8.3",
53
- "core-js": "3.29.1",
53
+ "core-js": "3.31.0",
54
54
  "del": "6.1.1",
55
55
  "dtslint": "4.2.1",
56
- "eslint": "8.36.0",
57
- "eslint-config-prettier": "8.7.0",
58
- "eslint-config-standard": "17.0.0",
56
+ "eslint": "8.42.0",
57
+ "eslint-config-prettier": "8.8.0",
58
+ "eslint-config-standard": "17.1.0",
59
59
  "eslint-plugin-import": "2.27.5",
60
60
  "eslint-plugin-mocha": "10.1.0",
61
- "eslint-plugin-n": "15.6.1",
61
+ "eslint-plugin-n": "16.0.0",
62
62
  "eslint-plugin-prettier": "4.2.1",
63
63
  "eslint-plugin-promise": "6.1.1",
64
- "expect-type": "0.15.0",
64
+ "expect-type": "0.16.0",
65
65
  "expr-eval": "2.0.2",
66
66
  "fancy-log": "2.0.0",
67
67
  "glob": "8.1.0",
@@ -69,13 +69,13 @@
69
69
  "gulp-babel": "8.0.0",
70
70
  "handlebars": "4.7.7",
71
71
  "jsep": "1.3.8",
72
- "karma": "6.4.1",
72
+ "karma": "6.4.2",
73
73
  "karma-browserstack-launcher": "1.6.0",
74
74
  "karma-firefox-launcher": "2.1.2",
75
75
  "karma-mocha": "2.0.1",
76
76
  "karma-mocha-reporter": "2.2.5",
77
77
  "karma-webpack": "5.0.0",
78
- "mkdirp": "2.1.5",
78
+ "mkdirp": "2.1.6",
79
79
  "mocha": "10.2.0",
80
80
  "mocha-junit-reporter": "2.2.0",
81
81
  "ndarray": "1.0.19",
@@ -85,12 +85,12 @@
85
85
  "ndarray-pack": "1.2.1",
86
86
  "numericjs": "1.2.6",
87
87
  "pad-right": "0.2.2",
88
- "prettier": "2.8.4",
88
+ "prettier": "2.8.8",
89
89
  "process": "0.11.10",
90
90
  "sylvester": "0.0.21",
91
91
  "ts-node": "10.9.1",
92
- "typescript": "4.9.5",
93
- "webpack": "5.76.1",
92
+ "typescript": "5.1.3",
93
+ "webpack": "5.86.0",
94
94
  "zeros": "1.0.0"
95
95
  },
96
96
  "type": "module",