mathjs 14.9.1 → 15.1.0

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 (146) hide show
  1. package/HISTORY.md +35 -0
  2. package/README.md +1 -1
  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/config.js +5 -1
  7. package/lib/cjs/core/function/config.js +4 -0
  8. package/lib/cjs/entry/dependenciesAny/dependenciesBernoulli.generated.js +25 -0
  9. package/lib/cjs/entry/dependenciesAny/dependenciesConstantNode.generated.js +2 -0
  10. package/lib/cjs/entry/dependenciesAny/dependenciesEqual.generated.js +0 -2
  11. package/lib/cjs/entry/dependenciesAny/dependenciesIsBounded.generated.js +17 -0
  12. package/lib/cjs/entry/dependenciesAny/dependenciesIsFinite.generated.js +21 -0
  13. package/lib/cjs/entry/dependenciesAny/dependenciesIsInteger.generated.js +2 -0
  14. package/lib/cjs/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +2 -0
  15. package/lib/cjs/entry/dependenciesAny/dependenciesSize.generated.js +0 -2
  16. package/lib/cjs/entry/dependenciesAny/dependenciesUnitClass.generated.js +0 -2
  17. package/lib/cjs/entry/dependenciesAny/dependenciesZeta.generated.js +2 -0
  18. package/lib/cjs/entry/dependenciesAny.generated.js +21 -0
  19. package/lib/cjs/entry/dependenciesNumber/dependenciesBernoulli.generated.js +21 -0
  20. package/lib/cjs/entry/dependenciesNumber/dependenciesConstantNode.generated.js +2 -0
  21. package/lib/cjs/entry/dependenciesNumber/dependenciesIsBounded.generated.js +17 -0
  22. package/lib/cjs/entry/dependenciesNumber/dependenciesIsFinite.generated.js +21 -0
  23. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +2 -0
  24. package/lib/cjs/entry/dependenciesNumber/dependenciesSize.generated.js +0 -2
  25. package/lib/cjs/entry/dependenciesNumber/dependenciesZeta.generated.js +2 -0
  26. package/lib/cjs/entry/dependenciesNumber.generated.js +21 -0
  27. package/lib/cjs/entry/impureFunctionsAny.generated.js +223 -218
  28. package/lib/cjs/entry/impureFunctionsNumber.generated.js +82 -77
  29. package/lib/cjs/entry/pureFunctionsAny.generated.js +717 -702
  30. package/lib/cjs/entry/pureFunctionsNumber.generated.js +155 -142
  31. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +6 -0
  32. package/lib/cjs/expression/embeddedDocs/function/combinatorics/stirlingS2.js +2 -2
  33. package/lib/cjs/expression/embeddedDocs/function/probability/bernoulli.js +14 -0
  34. package/lib/cjs/expression/embeddedDocs/function/utils/isBounded.js +14 -0
  35. package/lib/cjs/expression/embeddedDocs/function/utils/isFinite.js +14 -0
  36. package/lib/cjs/expression/embeddedDocs/function/utils/isNaN.js +1 -1
  37. package/lib/cjs/expression/embeddedDocs/function/utils/isNumeric.js +1 -1
  38. package/lib/cjs/expression/node/AccessorNode.js +36 -7
  39. package/lib/cjs/expression/node/ConstantNode.js +4 -4
  40. package/lib/cjs/expression/node/FunctionNode.js +20 -5
  41. package/lib/cjs/expression/node/IndexNode.js +1 -1
  42. package/lib/cjs/expression/parse.js +74 -46
  43. package/lib/cjs/factoriesAny.js +21 -0
  44. package/lib/cjs/factoriesNumber.js +23 -2
  45. package/lib/cjs/function/algebra/simplifyConstant.js +3 -2
  46. package/lib/cjs/function/algebra/sylvester.js +6 -5
  47. package/lib/cjs/function/arithmetic/nthRoots.js +5 -1
  48. package/lib/cjs/function/logical/nullish.js +2 -2
  49. package/lib/cjs/function/matrix/column.js +2 -1
  50. package/lib/cjs/function/matrix/dot.js +4 -9
  51. package/lib/cjs/function/matrix/flatten.js +6 -3
  52. package/lib/cjs/function/matrix/kron.js +31 -30
  53. package/lib/cjs/function/matrix/row.js +2 -1
  54. package/lib/cjs/function/matrix/size.js +11 -17
  55. package/lib/cjs/function/matrix/subset.js +21 -11
  56. package/lib/cjs/function/probability/bernoulli.js +108 -0
  57. package/lib/cjs/function/relational/equal.js +2 -3
  58. package/lib/cjs/function/special/zeta.js +3 -2
  59. package/lib/cjs/function/utils/isBounded.js +54 -0
  60. package/lib/cjs/function/utils/isFinite.js +50 -0
  61. package/lib/cjs/function/utils/isInteger.js +7 -15
  62. package/lib/cjs/function/utils/isNaN.js +1 -1
  63. package/lib/cjs/function/utils/isNumeric.js +1 -1
  64. package/lib/cjs/header.js +2 -2
  65. package/lib/cjs/json/replacer.js +1 -1
  66. package/lib/cjs/plain/number/probability.js +2 -2
  67. package/lib/cjs/plain/number/trigonometry.js +1 -1
  68. package/lib/cjs/type/fraction/function/fraction.js +1 -1
  69. package/lib/cjs/type/matrix/DenseMatrix.js +52 -41
  70. package/lib/cjs/type/matrix/MatrixIndex.js +19 -20
  71. package/lib/cjs/type/matrix/SparseMatrix.js +37 -11
  72. package/lib/cjs/type/unit/Unit.js +12 -8
  73. package/lib/cjs/utils/number.js +7 -7
  74. package/lib/cjs/utils/optimizeCallback.js +13 -1
  75. package/lib/cjs/version.js +1 -1
  76. package/lib/esm/core/config.js +5 -1
  77. package/lib/esm/core/function/config.js +4 -0
  78. package/lib/esm/entry/dependenciesAny/dependenciesBernoulli.generated.js +18 -0
  79. package/lib/esm/entry/dependenciesAny/dependenciesConstantNode.generated.js +2 -0
  80. package/lib/esm/entry/dependenciesAny/dependenciesEqual.generated.js +0 -2
  81. package/lib/esm/entry/dependenciesAny/dependenciesIsBounded.generated.js +10 -0
  82. package/lib/esm/entry/dependenciesAny/dependenciesIsFinite.generated.js +14 -0
  83. package/lib/esm/entry/dependenciesAny/dependenciesIsInteger.generated.js +2 -0
  84. package/lib/esm/entry/dependenciesAny/dependenciesSimplifyConstant.generated.js +2 -0
  85. package/lib/esm/entry/dependenciesAny/dependenciesSize.generated.js +0 -2
  86. package/lib/esm/entry/dependenciesAny/dependenciesUnitClass.generated.js +0 -2
  87. package/lib/esm/entry/dependenciesAny/dependenciesZeta.generated.js +2 -0
  88. package/lib/esm/entry/dependenciesAny.generated.js +3 -0
  89. package/lib/esm/entry/dependenciesNumber/dependenciesBernoulli.generated.js +14 -0
  90. package/lib/esm/entry/dependenciesNumber/dependenciesConstantNode.generated.js +2 -0
  91. package/lib/esm/entry/dependenciesNumber/dependenciesIsBounded.generated.js +10 -0
  92. package/lib/esm/entry/dependenciesNumber/dependenciesIsFinite.generated.js +14 -0
  93. package/lib/esm/entry/dependenciesNumber/dependenciesSimplifyConstant.generated.js +2 -0
  94. package/lib/esm/entry/dependenciesNumber/dependenciesSize.generated.js +0 -2
  95. package/lib/esm/entry/dependenciesNumber/dependenciesZeta.generated.js +2 -0
  96. package/lib/esm/entry/dependenciesNumber.generated.js +3 -0
  97. package/lib/esm/entry/impureFunctionsAny.generated.js +225 -220
  98. package/lib/esm/entry/impureFunctionsNumber.generated.js +84 -79
  99. package/lib/esm/entry/pureFunctionsAny.generated.js +714 -699
  100. package/lib/esm/entry/pureFunctionsNumber.generated.js +154 -141
  101. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +6 -0
  102. package/lib/esm/expression/embeddedDocs/function/combinatorics/stirlingS2.js +2 -2
  103. package/lib/esm/expression/embeddedDocs/function/probability/bernoulli.js +8 -0
  104. package/lib/esm/expression/embeddedDocs/function/utils/isBounded.js +8 -0
  105. package/lib/esm/expression/embeddedDocs/function/utils/isFinite.js +8 -0
  106. package/lib/esm/expression/embeddedDocs/function/utils/isNaN.js +1 -1
  107. package/lib/esm/expression/embeddedDocs/function/utils/isNumeric.js +1 -1
  108. package/lib/esm/expression/node/AccessorNode.js +36 -7
  109. package/lib/esm/expression/node/ConstantNode.js +4 -4
  110. package/lib/esm/expression/node/FunctionNode.js +20 -5
  111. package/lib/esm/expression/node/IndexNode.js +1 -1
  112. package/lib/esm/expression/parse.js +74 -46
  113. package/lib/esm/factoriesAny.js +3 -0
  114. package/lib/esm/factoriesNumber.js +3 -0
  115. package/lib/esm/function/algebra/simplifyConstant.js +3 -2
  116. package/lib/esm/function/algebra/sylvester.js +6 -5
  117. package/lib/esm/function/arithmetic/nthRoots.js +5 -1
  118. package/lib/esm/function/logical/nullish.js +2 -2
  119. package/lib/esm/function/matrix/column.js +2 -1
  120. package/lib/esm/function/matrix/dot.js +4 -9
  121. package/lib/esm/function/matrix/flatten.js +6 -3
  122. package/lib/esm/function/matrix/kron.js +31 -30
  123. package/lib/esm/function/matrix/row.js +2 -1
  124. package/lib/esm/function/matrix/size.js +11 -17
  125. package/lib/esm/function/matrix/subset.js +21 -11
  126. package/lib/esm/function/probability/bernoulli.js +102 -0
  127. package/lib/esm/function/relational/equal.js +2 -3
  128. package/lib/esm/function/special/zeta.js +3 -2
  129. package/lib/esm/function/utils/isBounded.js +48 -0
  130. package/lib/esm/function/utils/isFinite.js +44 -0
  131. package/lib/esm/function/utils/isInteger.js +7 -15
  132. package/lib/esm/function/utils/isNaN.js +1 -1
  133. package/lib/esm/function/utils/isNumeric.js +1 -1
  134. package/lib/esm/json/replacer.js +1 -1
  135. package/lib/esm/plain/number/probability.js +2 -2
  136. package/lib/esm/plain/number/trigonometry.js +1 -1
  137. package/lib/esm/type/fraction/function/fraction.js +1 -1
  138. package/lib/esm/type/matrix/DenseMatrix.js +52 -41
  139. package/lib/esm/type/matrix/MatrixIndex.js +20 -21
  140. package/lib/esm/type/matrix/SparseMatrix.js +37 -11
  141. package/lib/esm/type/unit/Unit.js +12 -8
  142. package/lib/esm/utils/number.js +7 -7
  143. package/lib/esm/utils/optimizeCallback.js +13 -1
  144. package/lib/esm/version.js +1 -1
  145. package/package.json +8 -8
  146. package/types/index.d.ts +535 -223
@@ -1,4 +1,4 @@
1
- import { isArray, isMatrix, isRange } from '../../utils/is.js';
1
+ import { isArray, isMatrix, isRange, isNumber, isString } from '../../utils/is.js';
2
2
  import { clone } from '../../utils/object.js';
3
3
  import { isInteger } from '../../utils/number.js';
4
4
  import { factory } from '../../utils/factory.js';
@@ -31,7 +31,7 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
31
31
  * @Constructor Index
32
32
  * @param {...*} ranges
33
33
  */
34
- function Index(ranges) {
34
+ function Index() {
35
35
  if (!(this instanceof Index)) {
36
36
  throw new SyntaxError('Constructor must be called with the new operator');
37
37
  }
@@ -39,7 +39,7 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
39
39
  this._sourceSize = [];
40
40
  this._isScalar = true;
41
41
  for (var i = 0, ii = arguments.length; i < ii; i++) {
42
- var arg = arguments[i];
42
+ var arg = i < 0 || arguments.length <= i ? undefined : arguments[i];
43
43
  var argIsArray = isArray(arg);
44
44
  var argIsMatrix = isMatrix(arg);
45
45
  var argType = typeof arg;
@@ -50,6 +50,7 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
50
50
  } else if (argIsArray || argIsMatrix) {
51
51
  // create matrix
52
52
  var m = void 0;
53
+ this._isScalar = false;
53
54
  if (getMatrixDataType(arg) === 'boolean') {
54
55
  if (argIsArray) m = _createImmutableMatrix(_booleansArrayToNumbersForIndex(arg).valueOf());
55
56
  if (argIsMatrix) m = _createImmutableMatrix(_booleansArrayToNumbersForIndex(arg._data).valueOf());
@@ -58,16 +59,10 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
58
59
  m = _createImmutableMatrix(arg.valueOf());
59
60
  }
60
61
  this._dimensions.push(m);
61
- // size
62
- var size = m.size();
63
- // scalar
64
- if (size.length !== 1 || size[0] !== 1 || sourceSize !== null) {
65
- this._isScalar = false;
66
- }
67
62
  } else if (argType === 'number') {
68
- this._dimensions.push(_createImmutableMatrix([arg]));
63
+ this._dimensions.push(arg);
69
64
  } else if (argType === 'bigint') {
70
- this._dimensions.push(_createImmutableMatrix([Number(arg)]));
65
+ this._dimensions.push(Number(arg));
71
66
  } else if (argType === 'string') {
72
67
  // object property (arguments.count should be 1)
73
68
  this._dimensions.push(arg);
@@ -87,12 +82,15 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
87
82
  function _createImmutableMatrix(arg) {
88
83
  // loop array elements
89
84
  for (var i = 0, l = arg.length; i < l; i++) {
90
- if (typeof arg[i] !== 'number' || !isInteger(arg[i])) {
85
+ if (!isNumber(arg[i]) || !isInteger(arg[i])) {
91
86
  throw new TypeError('Index parameters must be positive integer numbers');
92
87
  }
93
88
  }
94
89
  // create matrix
95
- return new ImmutableDenseMatrix(arg);
90
+ var matrix = new ImmutableDenseMatrix();
91
+ matrix._data = arg;
92
+ matrix._size = [arg.length];
93
+ return matrix;
96
94
  }
97
95
 
98
96
  /**
@@ -130,7 +128,7 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
130
128
  var size = [];
131
129
  for (var i = 0, ii = this._dimensions.length; i < ii; i++) {
132
130
  var d = this._dimensions[i];
133
- size[i] = typeof d === 'string' ? 1 : d.size()[0];
131
+ size[i] = isString(d) || isNumber(d) ? 1 : d.size()[0];
134
132
  }
135
133
  return size;
136
134
  };
@@ -144,7 +142,7 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
144
142
  var values = [];
145
143
  for (var i = 0, ii = this._dimensions.length; i < ii; i++) {
146
144
  var range = this._dimensions[i];
147
- values[i] = typeof range === 'string' ? range : range.max();
145
+ values[i] = isString(range) || isNumber(range) ? range : range.max();
148
146
  }
149
147
  return values;
150
148
  };
@@ -158,7 +156,7 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
158
156
  var values = [];
159
157
  for (var i = 0, ii = this._dimensions.length; i < ii; i++) {
160
158
  var range = this._dimensions[i];
161
- values[i] = typeof range === 'string' ? range : range.min();
159
+ values[i] = isString(range) || isNumber(range) ? range : range.min();
162
160
  }
163
161
  return values;
164
162
  };
@@ -183,10 +181,11 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
183
181
  * @returns {Range | null} range
184
182
  */
185
183
  Index.prototype.dimension = function (dim) {
186
- if (typeof dim !== 'number') {
184
+ var _this$_dimensions$dim;
185
+ if (!isNumber(dim)) {
187
186
  return null;
188
187
  }
189
- return this._dimensions[dim] || null;
188
+ return (_this$_dimensions$dim = this._dimensions[dim]) !== null && _this$_dimensions$dim !== void 0 ? _this$_dimensions$dim : null;
190
189
  };
191
190
 
192
191
  /**
@@ -194,7 +193,7 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
194
193
  * @returns {boolean} Returns true if the index is an object property
195
194
  */
196
195
  Index.prototype.isObjectProperty = function () {
197
- return this._dimensions.length === 1 && typeof this._dimensions[0] === 'string';
196
+ return this._dimensions.length === 1 && isString(this._dimensions[0]);
198
197
  };
199
198
 
200
199
  /**
@@ -228,7 +227,7 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
228
227
  var array = [];
229
228
  for (var i = 0, ii = this._dimensions.length; i < ii; i++) {
230
229
  var dimension = this._dimensions[i];
231
- array.push(typeof dimension === 'string' ? dimension : dimension.toArray());
230
+ array.push(isString(dimension) || isNumber(dimension) ? dimension : dimension.toArray());
232
231
  }
233
232
  return array;
234
233
  };
@@ -250,7 +249,7 @@ export var createIndexClass = /* #__PURE__ */factory(name, dependencies, _ref =>
250
249
  var strings = [];
251
250
  for (var i = 0, ii = this._dimensions.length; i < ii; i++) {
252
251
  var dimension = this._dimensions[i];
253
- if (typeof dimension === 'string') {
252
+ if (isString(dimension)) {
254
253
  strings.push(JSON.stringify(dimension));
255
254
  } else {
256
255
  strings.push(dimension.toString());
@@ -15,9 +15,27 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
15
15
  Matrix
16
16
  } = _ref;
17
17
  /**
18
- * Sparse Matrix implementation. This type implements
19
- * a [Compressed Column Storage](https://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_column_(CSC_or_CCS))
20
- * format for two-dimensional sparse matrices.
18
+ * Sparse Matrix implementation. This type (currently) implements 2D
19
+ * matrices only via the format known as
20
+ * [Compressed Column Storage](https://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_column_(CSC_or_CCS)).
21
+ *
22
+ * The structure/invariants of the internal data should be:
23
+ * 1. _values is an array of the nonzero values in order from top to bottom
24
+ * (of each column), left to right.
25
+ * 2. _index is an array of row numbers, of the same length as and
26
+ * corresponding positionally to _values.
27
+ * 3. _ptr is an array of length one more than the number of columns. For j
28
+ * less than the number of columns, the "half-open" span of indices
29
+ * _ptr[j] to _ptr[j+1] (i.e. including _ptr[j] if it is less than
30
+ * _ptr[j+1], but never including _ptr[j+1]) are the indices in _values
31
+ * of the nonzero elements in column j. Note there are no nonzero elements
32
+ * in column j exactly when _ptr[j] === _ptr[j+1], and that the final
33
+ * entry in _ptr is always exactly the number of nonzero entries in the
34
+ * matrix.
35
+ * 4. _size is a length-2 array consisting of the number of rows followed by
36
+ * the number of columns.
37
+ * 5. _datatype, if set, is the mathjs typeOf value of all entries of the
38
+ * SparseMatrix.
21
39
  * @class SparseMatrix
22
40
  */
23
41
  function SparseMatrix(data, datatype) {
@@ -135,7 +153,9 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
135
153
  } while (j < columns);
136
154
  }
137
155
  // store number of values in ptr
138
- matrix._ptr.push(matrix._index.length);
156
+ while (matrix._ptr.length <= columns) {
157
+ matrix._ptr.push(matrix._index.length);
158
+ }
139
159
  // size
140
160
  matrix._size = [rows, columns];
141
161
  }
@@ -298,12 +318,13 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
298
318
  var pv = [];
299
319
 
300
320
  // loop rows in resulting matrix
301
- rows.forEach(function (i, r) {
321
+ function rowsCallback(i, r) {
302
322
  // update permutation vector
303
323
  pv[i] = r[0];
304
324
  // mark i in workspace
305
325
  w[i] = true;
306
- });
326
+ }
327
+ if (Number.isInteger(rows)) rowsCallback(rows, [0]);else rows.forEach(rowsCallback);
307
328
 
308
329
  // result matrix arrays
309
330
  var values = mvalues ? [] : undefined;
@@ -311,7 +332,7 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
311
332
  var ptr = [];
312
333
 
313
334
  // loop columns in result matrix
314
- columns.forEach(function (j) {
335
+ function columnsCallback(j) {
315
336
  // update ptr
316
337
  ptr.push(index.length);
317
338
  // loop values in column j
@@ -328,7 +349,8 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
328
349
  }
329
350
  }
330
351
  }
331
- });
352
+ }
353
+ if (Number.isInteger(columns)) columnsCallback(columns);else columns.forEach(columnsCallback);
332
354
  // update ptr
333
355
  ptr.push(index.length);
334
356
 
@@ -402,7 +424,7 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
402
424
  if (iSize.length === 1) {
403
425
  // if the replacement index only has 1 dimension, go trough each one and set its value
404
426
  var range = index.dimension(0);
405
- range.forEach(function (dataIndex, subIndex) {
427
+ _forEachIndex(range, (dataIndex, subIndex) => {
406
428
  validateIndex(dataIndex);
407
429
  matrix.set([dataIndex, 0], submatrix[subIndex[0]], defaultValue);
408
430
  });
@@ -410,9 +432,9 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
410
432
  // if the replacement index has 2 dimensions, go through each one and set the value in the correct index
411
433
  var firstDimensionRange = index.dimension(0);
412
434
  var secondDimensionRange = index.dimension(1);
413
- firstDimensionRange.forEach(function (firstDataIndex, firstSubIndex) {
435
+ _forEachIndex(firstDimensionRange, (firstDataIndex, firstSubIndex) => {
414
436
  validateIndex(firstDataIndex);
415
- secondDimensionRange.forEach(function (secondDataIndex, secondSubIndex) {
437
+ _forEachIndex(secondDimensionRange, (secondDataIndex, secondSubIndex) => {
416
438
  validateIndex(secondDataIndex);
417
439
  matrix.set([firstDataIndex, secondDataIndex], submatrix[firstSubIndex[0]][secondSubIndex[0]], defaultValue);
418
440
  });
@@ -420,6 +442,10 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
420
442
  }
421
443
  }
422
444
  return matrix;
445
+ function _forEachIndex(index, callback) {
446
+ // iterate cases where index is a Matrix or a Number
447
+ if (isNumber(index)) callback(index, [0]);else index.forEach(callback);
448
+ }
423
449
  }
424
450
 
425
451
  /**
@@ -9,7 +9,7 @@ import { endsWith } from '../../utils/string.js';
9
9
  import { clone, hasOwnProperty } from '../../utils/object.js';
10
10
  import { createBigNumberPi as createPi } from '../../utils/bignumber/constants.js';
11
11
  var name = 'Unit';
12
- var dependencies = ['?on', 'config', 'addScalar', 'subtractScalar', 'multiplyScalar', 'divideScalar', 'pow', 'abs', 'fix', 'round', 'equal', 'isNumeric', 'format', 'toBest', 'number', 'Complex', 'BigNumber', 'Fraction'];
12
+ var dependencies = ['?on', 'config', 'addScalar', 'subtractScalar', 'multiplyScalar', 'divideScalar', 'pow', 'abs', 'fix', 'round', 'equal', 'isNumeric', 'format', 'number', 'Complex', 'BigNumber', 'Fraction'];
13
13
  export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref => {
14
14
  var {
15
15
  on,
@@ -25,13 +25,15 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
25
25
  equal,
26
26
  isNumeric,
27
27
  format,
28
- toBest,
29
28
  number: _number,
30
29
  Complex,
31
30
  BigNumber: _BigNumber,
32
31
  Fraction: _Fraction
33
32
  } = _ref;
34
33
  var toNumber = _number;
34
+ var fixPrefixDefault = false;
35
+ var skipAutomaticSimplificationDefault = true;
36
+
35
37
  /**
36
38
  * A unit can be constructed in the following ways:
37
39
  *
@@ -58,13 +60,13 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
58
60
  if (!(value === null || value === undefined || isNumeric(value) || isComplex(value))) {
59
61
  throw new TypeError('First parameter in Unit constructor must be number, BigNumber, Fraction, Complex, or undefined');
60
62
  }
61
- this.fixPrefix = false; // if true, function format will not search for the
63
+ this.fixPrefix = fixPrefixDefault; // if true, function format will not search for the
62
64
  // best prefix but leave it as initially provided.
63
65
  // fixPrefix is set true by the method Unit.to
64
66
 
65
67
  // The justification behind this is that if the constructor is explicitly called,
66
68
  // the caller wishes the units to be returned exactly as supplied.
67
- this.skipAutomaticSimplification = true;
69
+ this.skipAutomaticSimplification = skipAutomaticSimplificationDefault;
68
70
  if (valuelessUnit === undefined) {
69
71
  this.units = [];
70
72
  this.dimensions = BASE_DIMENSIONS.map(x => 0);
@@ -855,14 +857,15 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
855
857
  * Get a JSON representation of the unit
856
858
  * @memberof Unit
857
859
  * @returns {Object} Returns a JSON object structured as:
858
- * `{"mathjs": "Unit", "value": 2, "unit": "cm", "fixPrefix": false}`
860
+ * `{"mathjs": "Unit", "value": 2, "unit": "cm", "fixPrefix": false, "skipSimp": true}`
859
861
  */
860
862
  Unit.prototype.toJSON = function () {
861
863
  return {
862
864
  mathjs: 'Unit',
863
865
  value: this._denormalize(this.value),
864
866
  unit: this.units.length > 0 ? this.formatUnits() : null,
865
- fixPrefix: this.fixPrefix
867
+ fixPrefix: this.fixPrefix,
868
+ skipSimp: this.skipAutomaticSimplification
866
869
  };
867
870
  };
868
871
 
@@ -874,9 +877,10 @@ export var createUnitClass = /* #__PURE__ */factory(name, dependencies, _ref =>
874
877
  * @return {Unit}
875
878
  */
876
879
  Unit.fromJSON = function (json) {
877
- var _json$unit;
880
+ var _json$unit, _json$fixPrefix, _json$skipSimp;
878
881
  var unit = new Unit(json.value, (_json$unit = json.unit) !== null && _json$unit !== void 0 ? _json$unit : undefined);
879
- unit.fixPrefix = json.fixPrefix || false;
882
+ unit.fixPrefix = (_json$fixPrefix = json.fixPrefix) !== null && _json$fixPrefix !== void 0 ? _json$fixPrefix : fixPrefixDefault;
883
+ unit.skipAutomaticSimplification = (_json$skipSimp = json.skipSimp) !== null && _json$skipSimp !== void 0 ? _json$skipSimp : skipAutomaticSimplificationDefault;
880
884
  return unit;
881
885
  };
882
886
 
@@ -13,7 +13,7 @@ export function isInteger(value) {
13
13
  if (typeof value === 'boolean') {
14
14
  return true;
15
15
  }
16
- return isFinite(value) ? value === Math.round(value) : false;
16
+ return Number.isFinite(value) ? value === Math.round(value) : false;
17
17
  }
18
18
 
19
19
  /**
@@ -105,7 +105,7 @@ export var cbrt = Math.cbrt || function cbrt(x) {
105
105
  if (negate) {
106
106
  x = -x;
107
107
  }
108
- if (isFinite(x)) {
108
+ if (Number.isFinite(x)) {
109
109
  result = Math.exp(Math.log(x) / 3);
110
110
  // from https://en.wikipedia.org/wiki/Cube_root#Numerical_methods
111
111
  result = (x / (result * result) + 2 * result) / 3;
@@ -381,7 +381,7 @@ export function splitNumber(value) {
381
381
  * @param {number} [precision] Optional number of significant figures to return.
382
382
  */
383
383
  export function toEngineering(value, precision) {
384
- if (isNaN(value) || !isFinite(value)) {
384
+ if (isNaN(value) || !Number.isFinite(value)) {
385
385
  return String(value);
386
386
  }
387
387
  var split = splitNumber(value);
@@ -430,7 +430,7 @@ export function toEngineering(value, precision) {
430
430
  * decimal point. null by default.
431
431
  */
432
432
  export function toFixed(value, precision) {
433
- if (isNaN(value) || !isFinite(value)) {
433
+ if (isNaN(value) || !Number.isFinite(value)) {
434
434
  return String(value);
435
435
  }
436
436
  var splitValue = splitNumber(value);
@@ -465,7 +465,7 @@ export function toFixed(value, precision) {
465
465
  * is used.
466
466
  */
467
467
  export function toExponential(value, precision) {
468
- if (isNaN(value) || !isFinite(value)) {
468
+ if (isNaN(value) || !Number.isFinite(Number(value))) {
469
469
  return String(value);
470
470
  }
471
471
 
@@ -496,7 +496,7 @@ export function toExponential(value, precision) {
496
496
  * @return {string}
497
497
  */
498
498
  export function toPrecision(value, precision, options) {
499
- if (isNaN(value) || !isFinite(value)) {
499
+ if (isNaN(value) || !Number.isFinite(value)) {
500
500
  return String(value);
501
501
  }
502
502
 
@@ -635,7 +635,7 @@ export function nearlyEqual(a, b) {
635
635
  if (isNaN(a) || isNaN(b)) {
636
636
  return false;
637
637
  }
638
- if (!isFinite(a) || !isFinite(b)) {
638
+ if (!Number.isFinite(a) || !Number.isFinite(b)) {
639
639
  return a === b;
640
640
  }
641
641
  if (a === b) {
@@ -17,7 +17,19 @@ export function optimizeCallback(callback, array, name, isUnary) {
17
17
  if (isUnary) {
18
18
  numberOfArguments = 1;
19
19
  } else {
20
- var firstIndex = (array.isMatrix ? array.size() : arraySize(array)).map(() => 0);
20
+ var size = array.isMatrix ? array.size() : arraySize(array);
21
+
22
+ // Check the size of the last dimension to see if the array/matrix is empty
23
+ var isEmpty = size.length ? size[size.length - 1] === 0 : true;
24
+ if (isEmpty) {
25
+ // don't optimize callbacks for empty arrays/matrix, as they will never be called
26
+ // and in fact will throw an exception when we try to access the first element below
27
+ return {
28
+ isUnary,
29
+ fn: callback
30
+ };
31
+ }
32
+ var firstIndex = size.map(() => 0);
21
33
  var firstValue = array.isMatrix ? array.get(firstIndex) : get(array, firstIndex);
22
34
  numberOfArguments = _findNumberOfArgumentsTyped(callback, firstValue, firstIndex, array);
23
35
  }
@@ -1,3 +1,3 @@
1
- export var version = '14.9.1';
1
+ export var version = '15.1.0';
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": "14.9.1",
3
+ "version": "15.1.0",
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",
@@ -36,16 +36,16 @@
36
36
  "typed-function": "^4.2.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@babel/core": "7.28.4",
39
+ "@babel/core": "7.28.5",
40
40
  "@babel/plugin-transform-object-assign": "7.27.1",
41
41
  "@babel/plugin-transform-optional-catch-binding": "7.27.1",
42
- "@babel/plugin-transform-runtime": "7.28.3",
43
- "@babel/preset-env": "7.28.3",
42
+ "@babel/plugin-transform-runtime": "7.28.5",
43
+ "@babel/preset-env": "7.28.5",
44
44
  "@babel/register": "7.28.3",
45
45
  "@types/assert": "1.5.11",
46
46
  "@types/mocha": "10.0.10",
47
- "@typescript-eslint/eslint-plugin": "8.46.0",
48
- "@typescript-eslint/parser": "8.46.0",
47
+ "@typescript-eslint/eslint-plugin": "8.46.3",
48
+ "@typescript-eslint/parser": "8.46.3",
49
49
  "assert": "2.1.0",
50
50
  "babel-loader": "10.0.0",
51
51
  "c8": "10.1.3",
@@ -77,7 +77,7 @@
77
77
  "karma-webdriver-launcher": "1.0.8",
78
78
  "karma-webpack": "5.0.1",
79
79
  "mkdirp": "3.0.1",
80
- "mocha": "11.7.4",
80
+ "mocha": "11.7.5",
81
81
  "mocha-junit-reporter": "2.2.1",
82
82
  "ndarray": "1.0.19",
83
83
  "ndarray-determinant": "1.0.0",
@@ -89,7 +89,7 @@
89
89
  "process": "0.11.10",
90
90
  "sinon": "21.0.0",
91
91
  "sylvester": "0.0.21",
92
- "tinybench": "5.0.1",
92
+ "tinybench": "5.1.0",
93
93
  "ts-node": "10.9.2",
94
94
  "typescript": "5.9.3",
95
95
  "webpack": "5.102.1",