mathjs 11.8.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 (63) hide show
  1. package/HISTORY.md +17 -1
  2. package/lib/browser/math.js +1 -1
  3. package/lib/browser/math.js.LICENSE.txt +2 -2
  4. package/lib/browser/math.js.map +1 -1
  5. package/lib/cjs/entry/dependenciesAny/dependenciesDistance.generated.js +2 -2
  6. package/lib/cjs/entry/pureFunctionsAny.generated.js +2 -2
  7. package/lib/cjs/expression/Parser.js +1 -1
  8. package/lib/cjs/expression/function/parser.js +1 -1
  9. package/lib/cjs/expression/transform/filter.transform.js +4 -13
  10. package/lib/cjs/expression/transform/forEach.transform.js +3 -12
  11. package/lib/cjs/expression/transform/map.transform.js +4 -13
  12. package/lib/cjs/function/algebra/derivative.js +2 -2
  13. package/lib/cjs/function/algebra/leafCount.js +1 -1
  14. package/lib/cjs/function/algebra/polynomialRoot.js +1 -1
  15. package/lib/cjs/function/algebra/rationalize.js +4 -4
  16. package/lib/cjs/function/algebra/resolve.js +1 -1
  17. package/lib/cjs/function/algebra/simplify.js +7 -7
  18. package/lib/cjs/function/algebra/simplifyConstant.js +2 -2
  19. package/lib/cjs/function/algebra/simplifyCore.js +2 -2
  20. package/lib/cjs/function/algebra/symbolicEqual.js +8 -8
  21. package/lib/cjs/function/geometry/distance.js +21 -17
  22. package/lib/cjs/function/matrix/filter.js +2 -11
  23. package/lib/cjs/function/matrix/forEach.js +3 -12
  24. package/lib/cjs/function/matrix/map.js +6 -38
  25. package/lib/cjs/function/matrix/sqrtm.js +1 -1
  26. package/lib/cjs/header.js +2 -2
  27. package/lib/cjs/type/bignumber/function/bignumber.js +7 -0
  28. package/lib/cjs/type/fraction/function/fraction.js +8 -1
  29. package/lib/cjs/type/number.js +7 -3
  30. package/lib/cjs/type/unit/function/splitUnit.js +1 -1
  31. package/lib/cjs/utils/applyCallback.js +73 -0
  32. package/lib/cjs/utils/bignumber/formatter.js +4 -3
  33. package/lib/cjs/version.js +1 -1
  34. package/lib/esm/entry/dependenciesAny/dependenciesDistance.generated.js +2 -2
  35. package/lib/esm/entry/pureFunctionsAny.generated.js +2 -2
  36. package/lib/esm/expression/Parser.js +1 -1
  37. package/lib/esm/expression/function/parser.js +1 -1
  38. package/lib/esm/expression/transform/filter.transform.js +4 -13
  39. package/lib/esm/expression/transform/forEach.transform.js +3 -12
  40. package/lib/esm/expression/transform/map.transform.js +4 -13
  41. package/lib/esm/function/algebra/derivative.js +2 -2
  42. package/lib/esm/function/algebra/leafCount.js +1 -1
  43. package/lib/esm/function/algebra/polynomialRoot.js +1 -1
  44. package/lib/esm/function/algebra/rationalize.js +4 -4
  45. package/lib/esm/function/algebra/resolve.js +1 -1
  46. package/lib/esm/function/algebra/simplify.js +7 -7
  47. package/lib/esm/function/algebra/simplifyConstant.js +2 -2
  48. package/lib/esm/function/algebra/simplifyCore.js +2 -2
  49. package/lib/esm/function/algebra/symbolicEqual.js +8 -8
  50. package/lib/esm/function/geometry/distance.js +21 -17
  51. package/lib/esm/function/matrix/filter.js +2 -11
  52. package/lib/esm/function/matrix/forEach.js +3 -12
  53. package/lib/esm/function/matrix/map.js +6 -38
  54. package/lib/esm/function/matrix/sqrtm.js +1 -1
  55. package/lib/esm/type/bignumber/function/bignumber.js +5 -0
  56. package/lib/esm/type/fraction/function/fraction.js +6 -1
  57. package/lib/esm/type/number.js +5 -3
  58. package/lib/esm/type/unit/function/splitUnit.js +1 -1
  59. package/lib/esm/utils/applyCallback.js +67 -0
  60. package/lib/esm/utils/bignumber/formatter.js +4 -3
  61. package/lib/esm/version.js +1 -1
  62. package/package.json +19 -19
  63. package/types/index.d.ts +8 -8
@@ -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
  },
@@ -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
  }
@@ -1,3 +1,3 @@
1
- export var version = '11.8.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.8.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.4",
40
- "@babel/plugin-transform-object-assign": "7.18.6",
41
- "@babel/plugin-transform-runtime": "7.21.4",
42
- "@babel/preset-env": "7.21.4",
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.57.0",
47
- "@typescript-eslint/parser": "5.57.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.37.0",
56
+ "eslint": "8.42.0",
57
57
  "eslint-config-prettier": "8.8.0",
58
- "eslint-config-standard": "17.0.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.7.0",
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,7 +69,7 @@
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",
@@ -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.7",
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": "5.0.3",
93
- "webpack": "5.77.0",
92
+ "typescript": "5.1.3",
93
+ "webpack": "5.86.0",
94
94
  "zeros": "1.0.0"
95
95
  },
96
96
  "type": "module",
package/types/index.d.ts CHANGED
@@ -1581,12 +1581,14 @@ declare namespace math {
1581
1581
  * a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b,
1582
1582
  * c)
1583
1583
  * @param x Coordinates of the first point
1584
- * @param y Coordinates of the second point
1584
+ * @param y Coordinates of the second point OR coefficients of a line in 3D OR first end-point of a line if the calculation is for distance between point and a line in 2D
1585
+ * @param z Coordinates of second end-point of a line if the calculation is for distance between point and a line in 2D
1585
1586
  * @returns Returns the distance from two/three points
1586
1587
  */
1587
1588
  distance(
1588
1589
  x: MathCollection | object,
1589
- y: MathCollection | object
1590
+ y: MathCollection | object,
1591
+ z?: MathCollection | object
1590
1592
  ): number | BigNumber
1591
1593
 
1592
1594
  /**
@@ -2596,8 +2598,7 @@ declare namespace math {
2596
2598
  * @param args A single matrix or multiple scalar values
2597
2599
  * @returns The maximum value
2598
2600
  */
2599
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2600
- max(...args: MathType[]): any
2601
+ max<T extends MathType[]>(...args: T): T[number]
2601
2602
  /**
2602
2603
  * @param A A single matrix
2603
2604
  * @param dim The maximum over the selected dimension
@@ -2639,14 +2640,13 @@ declare namespace math {
2639
2640
 
2640
2641
  /**
2641
2642
  * Compute the minimum value of a matrix or a list of values. In case of
2642
- * a multi dimensional array, the minimun of the flattened array will be
2643
- * calculated. When dim is provided, the minimun over the selected
2643
+ * a multi dimensional array, the minimum of the flattened array will be
2644
+ * calculated. When dim is provided, the minimum over the selected
2644
2645
  * dimension will be calculated. Parameter dim is zero-based.
2645
2646
  * @param args A single matrix or or multiple scalar values
2646
2647
  * @returns The minimum value
2647
2648
  */
2648
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2649
- min(...args: MathType[]): any
2649
+ min<T extends MathType[]>(...args: T): T[number]
2650
2650
  /**
2651
2651
  * @param A A single matrix
2652
2652
  * @param dim The minimum over the selected dimension