mathjs 11.0.0 → 11.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/CONTRIBUTING.md +1 -4
  2. package/HISTORY.md +27 -0
  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/create.js +1 -0
  7. package/lib/cjs/core/function/typed.js +3 -0
  8. package/lib/cjs/entry/typeChecks.js +6 -0
  9. package/lib/cjs/expression/embeddedDocs/construction/index.js +1 -1
  10. package/lib/cjs/function/algebra/derivative.js +3 -3
  11. package/lib/cjs/function/algebra/simplify.js +3 -1
  12. package/lib/cjs/function/algebra/symbolicEqual.js +5 -6
  13. package/lib/cjs/function/arithmetic/fix.js +1 -1
  14. package/lib/cjs/function/arithmetic/floor.js +1 -1
  15. package/lib/cjs/function/arithmetic/invmod.js +1 -1
  16. package/lib/cjs/function/arithmetic/nthRoot.js +3 -3
  17. package/lib/cjs/function/arithmetic/nthRoots.js +2 -2
  18. package/lib/cjs/function/bitwise/bitNot.js +1 -1
  19. package/lib/cjs/function/bitwise/leftShift.js +1 -1
  20. package/lib/cjs/function/bitwise/rightArithShift.js +1 -1
  21. package/lib/cjs/function/bitwise/rightLogShift.js +1 -1
  22. package/lib/cjs/function/geometry/distance.js +2 -2
  23. package/lib/cjs/function/matrix/diff.js +1 -1
  24. package/lib/cjs/function/matrix/rotate.js +5 -5
  25. package/lib/cjs/function/string/format.js +2 -2
  26. package/lib/cjs/function/string/hex.js +1 -2
  27. package/lib/cjs/function/trigonometry/acot.js +2 -3
  28. package/lib/cjs/function/trigonometry/acsc.js +2 -3
  29. package/lib/cjs/function/trigonometry/asec.js +2 -2
  30. package/lib/cjs/function/trigonometry/asin.js +1 -1
  31. package/lib/cjs/function/trigonometry/atan.js +1 -2
  32. package/lib/cjs/function/trigonometry/atan2.js +1 -1
  33. package/lib/cjs/function/utils/clone.js +1 -1
  34. package/lib/cjs/function/utils/hasNumericValue.js +1 -1
  35. package/lib/cjs/function/utils/isInteger.js +1 -1
  36. package/lib/cjs/function/utils/isNaN.js +1 -1
  37. package/lib/cjs/function/utils/isNegative.js +1 -1
  38. package/lib/cjs/function/utils/isNumeric.js +1 -1
  39. package/lib/cjs/function/utils/isPositive.js +1 -1
  40. package/lib/cjs/function/utils/isZero.js +11 -11
  41. package/lib/cjs/header.js +2 -2
  42. package/lib/cjs/type/unit/Unit.js +30 -25
  43. package/lib/cjs/type/unit/function/unit.js +5 -2
  44. package/lib/cjs/utils/is.js +5 -0
  45. package/lib/cjs/version.js +1 -1
  46. package/lib/esm/core/create.js +2 -1
  47. package/lib/esm/core/function/typed.js +4 -1
  48. package/lib/esm/entry/typeChecks.js +1 -1
  49. package/lib/esm/expression/embeddedDocs/construction/index.js +1 -1
  50. package/lib/esm/function/algebra/derivative.js +3 -3
  51. package/lib/esm/function/algebra/simplify.js +3 -1
  52. package/lib/esm/function/algebra/symbolicEqual.js +5 -6
  53. package/lib/esm/function/arithmetic/fix.js +1 -1
  54. package/lib/esm/function/arithmetic/floor.js +1 -1
  55. package/lib/esm/function/arithmetic/invmod.js +1 -1
  56. package/lib/esm/function/arithmetic/nthRoot.js +3 -3
  57. package/lib/esm/function/arithmetic/nthRoots.js +2 -2
  58. package/lib/esm/function/bitwise/bitNot.js +1 -1
  59. package/lib/esm/function/bitwise/leftShift.js +1 -1
  60. package/lib/esm/function/bitwise/rightArithShift.js +1 -1
  61. package/lib/esm/function/bitwise/rightLogShift.js +1 -1
  62. package/lib/esm/function/geometry/distance.js +2 -2
  63. package/lib/esm/function/matrix/diff.js +1 -1
  64. package/lib/esm/function/matrix/rotate.js +5 -5
  65. package/lib/esm/function/string/format.js +2 -2
  66. package/lib/esm/function/string/hex.js +1 -2
  67. package/lib/esm/function/trigonometry/acot.js +2 -3
  68. package/lib/esm/function/trigonometry/acsc.js +2 -3
  69. package/lib/esm/function/trigonometry/asec.js +2 -2
  70. package/lib/esm/function/trigonometry/asin.js +1 -1
  71. package/lib/esm/function/trigonometry/atan.js +1 -2
  72. package/lib/esm/function/trigonometry/atan2.js +1 -1
  73. package/lib/esm/function/utils/clone.js +1 -1
  74. package/lib/esm/function/utils/hasNumericValue.js +1 -1
  75. package/lib/esm/function/utils/isInteger.js +1 -1
  76. package/lib/esm/function/utils/isNaN.js +1 -1
  77. package/lib/esm/function/utils/isNegative.js +1 -1
  78. package/lib/esm/function/utils/isNumeric.js +1 -1
  79. package/lib/esm/function/utils/isPositive.js +1 -1
  80. package/lib/esm/function/utils/isZero.js +11 -11
  81. package/lib/esm/type/unit/Unit.js +25 -24
  82. package/lib/esm/type/unit/function/unit.js +5 -2
  83. package/lib/esm/utils/is.js +3 -0
  84. package/lib/esm/version.js +1 -1
  85. package/package.json +17 -18
  86. package/types/index.d.ts +33 -19
  87. package/types/index.ts +123 -95
  88. package/types/tsconfig.json +4 -1
@@ -122,6 +122,7 @@ function create(factories, config) {
122
122
  isOperatorNode: _is.isOperatorNode,
123
123
  isParenthesisNode: _is.isParenthesisNode,
124
124
  isRangeNode: _is.isRangeNode,
125
+ isRelationalNode: _is.isRelationalNode,
125
126
  isSymbolNode: _is.isSymbolNode,
126
127
  isChain: _is.isChain
127
128
  }); // load config function and apply provided config
@@ -197,6 +197,9 @@ var createTyped = /* #__PURE__ */(0, _factory.factory)('typed', dependencies, fu
197
197
  }, {
198
198
  name: 'RangeNode',
199
199
  test: _is.isRangeNode
200
+ }, {
201
+ name: 'RelationalNode',
202
+ test: _is.isRelationalNode
200
203
  }, {
201
204
  name: 'SymbolNode',
202
205
  test: _is.isSymbolNode
@@ -195,6 +195,12 @@ Object.defineProperty(exports, "isRegExp", {
195
195
  return _is.isRegExp;
196
196
  }
197
197
  });
198
+ Object.defineProperty(exports, "isRelationalNode", {
199
+ enumerable: true,
200
+ get: function get() {
201
+ return _is.isRelationalNode;
202
+ }
203
+ });
198
204
  Object.defineProperty(exports, "isResultSet", {
199
205
  enumerable: true,
200
206
  get: function get() {
@@ -9,7 +9,7 @@ var indexDocs = {
9
9
  category: 'Construction',
10
10
  syntax: ['[start]', '[start:end]', '[start:step:end]', '[start1, start 2, ...]', '[start1:end1, start2:end2, ...]', '[start1:step1:end1, start2:step2:end2, ...]'],
11
11
  description: 'Create an index to get or replace a subset of a matrix',
12
- examples: ['[]', '[1, 2, 3]', 'A = [1, 2, 3; 4, 5, 6]', 'A[1, :]', 'A[1, 2] = 50', 'A[0:2, 0:2] = ones(2, 2)'],
12
+ examples: ['[1, 2, 3]', 'A = [1, 2, 3; 4, 5, 6]', 'A[1, :]', 'A[1, 2] = 50', 'A[1:2, 1:2] = ones(2, 2)'],
13
13
  seealso: ['bignumber', 'boolean', 'complex', 'matrix,', 'number', 'range', 'string', 'unit']
14
14
  };
15
15
  exports.indexDocs = indexDocs;
@@ -42,9 +42,9 @@ var createDerivative = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
42
42
  *
43
43
  * Examples:
44
44
  *
45
- * math.derivative('x^2', 'x') // Node {2 * x}
46
- * math.derivative('x^2', 'x', {simplify: false}) // Node {2 * 1 * x ^ (2 - 1)
47
- * math.derivative('sin(2x)', 'x')) // Node {2 * cos(2 * x)}
45
+ * math.derivative('x^2', 'x') // Node '2 * x'
46
+ * math.derivative('x^2', 'x', {simplify: false}) // Node '2 * 1 * x ^ (2 - 1)'
47
+ * math.derivative('sin(2x)', 'x')) // Node '2 * cos(2 * x)'
48
48
  * math.derivative('2*x', 'x').evaluate() // number 2
49
49
  * math.derivative('x^2', 'x').evaluate({x: 4}) // number 8
50
50
  * const f = math.parse('x^2')
@@ -167,8 +167,10 @@ var createSimplify = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
167
167
  *
168
168
  * @param {Node | string} expr
169
169
  * The expression to be simplified
170
- * @param {Array<{l:string, r: string} | string | function>} [rules]
170
+ * @param {SimplifyRule[]} [rules]
171
171
  * Optional list with custom rules
172
+ * @param {Object} [scope] Optional scope with variables
173
+ * @param {SimplifyOptions} [options] Optional configuration settings
172
174
  * @return {Node} Returns the simplified form of `expr`
173
175
  */
174
176
 
@@ -38,12 +38,11 @@ var createSymbolicEqual = /* #__PURE__ */(0, _factory.factory)(name, dependencie
38
38
  *
39
39
  * Examples:
40
40
  *
41
- * symbolicEqual('x*y', 'y*x') // true
42
- * symbolicEqual('x*y', 'y*x', {context: {multiply: {commutative: false}}})
43
- * //false
44
- * symbolicEqual('x/y', '(y*x^(-1))^(-1)') // true
45
- * symbolicEqual('abs(x)','x') // false
46
- * symbolicEqual('abs(x)','x', simplify.positiveContext) // true
41
+ * symbolicEqual('x*y', 'y*x') // Returns true
42
+ * symbolicEqual('x*y', 'y*x', {context: {multiply: {commutative: false}}}) // Returns false
43
+ * symbolicEqual('x/y', '(y*x^(-1))^(-1)') // Returns true
44
+ * symbolicEqual('abs(x)','x') // Returns false
45
+ * symbolicEqual('abs(x)','x', simplify.positiveContext) // Returns true
47
46
  *
48
47
  * See also:
49
48
  *
@@ -73,7 +73,7 @@ var createFix = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functio
73
73
  *
74
74
  * const c = math.complex(3.22, -2.78)
75
75
  * math.fix(c) // returns Complex 3 - 2i
76
- * math.fix(c, 1) // returns Complex 3.2 - 2.7i
76
+ * math.fix(c, 1) // returns Complex 3.2 -2.7i
77
77
  *
78
78
  * math.fix([3.2, 3.8, -4.7]) // returns Array [3, 3, -4]
79
79
  * math.fix([3.2, 3.8, -4.7], 1) // returns Array [3.2, 3.8, -4.7]
@@ -109,7 +109,7 @@ var createFloor = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
109
109
  *
110
110
  * const c = math.complex(3.24, -2.71)
111
111
  * math.floor(c) // returns Complex 3 - 3i
112
- * math.floor(c, 1) // returns Complex 3.2 - 2.8i
112
+ * math.floor(c, 1) // returns Complex 3.2 -2.8i
113
113
  *
114
114
  * math.floor([3.2, 3.8, -4.7]) // returns Array [3, 3, -5]
115
115
  * math.floor([3.21, 3.82, -4.71], 1) // returns Array [3.2, 3.8, -4.8]
@@ -35,7 +35,7 @@ var createInvmod = /* #__PURE__ */(0, _factory.factory)(name, dependencies, func
35
35
  * Examples:
36
36
  *
37
37
  * math.invmod(8, 12) // returns NaN
38
- * math.invmod(7, 13) // return 2
38
+ * math.invmod(7, 13) // returns 2
39
39
  * math.invmod(15151, 15122) // returns 10429
40
40
  *
41
41
  * See also:
@@ -61,9 +61,9 @@ var createNthRoot = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fun
61
61
  *
62
62
  * Examples:
63
63
  *
64
- * math.nthRoot(9, 2) // returns 3, as 3^2 == 9
65
- * math.sqrt(9) // returns 3, as 3^2 == 9
66
- * math.nthRoot(64, 3) // returns 4, as 4^3 == 64
64
+ * math.nthRoot(9, 2) // returns 3 (since 3^2 == 9)
65
+ * math.sqrt(9) // returns 3 (since 3^2 == 9)
66
+ * math.nthRoot(64, 3) // returns 4 (since 4^3 == 64)
67
67
  *
68
68
  * See also:
69
69
  *
@@ -98,12 +98,12 @@ var createNthRoots = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
98
98
  * // {re: 1, im: 0},
99
99
  * // {re: -1, im: 0}
100
100
  * // ]
101
- * nthRoots(1, 3)
101
+ * math.nthRoots(1, 3)
102
102
  * // returns [
103
103
  * // { re: 1, im: 0 },
104
104
  * // { re: -0.4999999999999998, im: 0.8660254037844387 },
105
105
  * // { re: -0.5000000000000004, im: -0.8660254037844385 }
106
- * ]
106
+ * // ]
107
107
  *
108
108
  * See also:
109
109
  *
@@ -31,7 +31,7 @@ var createBitNot = /* #__PURE__ */(0, _factory.factory)(name, dependencies, func
31
31
  *
32
32
  * math.bitNot(1) // returns number -2
33
33
  *
34
- * math.bitNot([2, -3, 4]) // returns Array [-3, 2, 5]
34
+ * math.bitNot([2, -3, 4]) // returns Array [-3, 2, -5]
35
35
  *
36
36
  * See also:
37
37
  *
@@ -78,7 +78,7 @@ var createLeftShift = /* #__PURE__ */(0, _factory.factory)(name, dependencies, f
78
78
  *
79
79
  * math.leftShift(1, 2) // returns number 4
80
80
  *
81
- * math.leftShift([1, 2, 3], 4) // returns Array [16, 32, 64]
81
+ * math.leftShift([1, 2, 4], 4) // returns Array [16, 32, 64]
82
82
  *
83
83
  * See also:
84
84
  *
@@ -78,7 +78,7 @@ var createRightArithShift = /* #__PURE__ */(0, _factory.factory)(name, dependenc
78
78
  *
79
79
  * math.rightArithShift(4, 2) // returns number 1
80
80
  *
81
- * math.rightArithShift([16, -32, 64], 4) // returns Array [1, -2, 3]
81
+ * math.rightArithShift([16, -32, 64], 4) // returns Array [1, -2, 4]
82
82
  *
83
83
  * See also:
84
84
  *
@@ -76,7 +76,7 @@ var createRightLogShift = /* #__PURE__ */(0, _factory.factory)(name, dependencie
76
76
  *
77
77
  * math.rightLogShift(4, 2) // returns number 1
78
78
  *
79
- * math.rightLogShift([16, -32, 64], 4) // returns Array [1, 2, 3]
79
+ * math.rightLogShift([16, 32, 64], 4) // returns Array [1, 2, 4]
80
80
  *
81
81
  * See also:
82
82
  *
@@ -48,11 +48,11 @@ var createDistance = /* #__PURE__ */(0, _factory.factory)(name, dependencies, fu
48
48
  * math.distance({pointX: 2, pointY: 5, pointZ: 9}, {x0: 4, y0: 6, z0: 3, a: 4, b: 2, c: 0})
49
49
  *
50
50
  * Examples:
51
- * math.distance([0,0], [4,4]) // Returns 5.6569
51
+ * math.distance([0,0], [4,4]) // Returns 5.656854249492381
52
52
  * math.distance(
53
53
  * {pointOneX: 0, pointOneY: 0},
54
54
  * {pointTwoX: 10, pointTwoY: 10}) // Returns 14.142135623730951
55
- * math.distance([1, 0, 1], [4, -2, 2]) // Returns 3.74166
55
+ * math.distance([1, 0, 1], [4, -2, 2]) // Returns 3.7416573867739413
56
56
  * math.distance(
57
57
  * {pointOneX: 4, pointOneY: 5, pointOneZ: 8},
58
58
  * {pointTwoX: 2, pointTwoY: 7, pointTwoZ: 9}) // Returns 3
@@ -37,7 +37,7 @@ var createDiff = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
37
37
  *
38
38
  * const arr = [1, 2, 4, 7, 0]
39
39
  * math.diff(arr) // returns [1, 2, 3, -7] (no dimension passed so 0 is assumed)
40
- * math.diff(math.matrix(arr)) // returns math.matrix([1, 2, 3, -7])
40
+ * math.diff(math.matrix(arr)) // returns Matrix [1, 2, 3, -7]
41
41
  *
42
42
  * const arr = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [9, 8, 7, 6, 4]]
43
43
  * math.diff(arr) // returns [[0, 0, 0, 0, 0], [8, 6, 4, 2, -1]]
@@ -27,13 +27,13 @@ var createRotate = /* #__PURE__ */(0, _factory.factory)(name, dependencies, func
27
27
  *
28
28
  * Examples:
29
29
  *
30
- * math.rotate([11, 12], math.pi / 2) // returns matrix([-12, 11])
31
- * math.rotate(matrix([11, 12]), math.pi / 2) // returns matrix([-12, 11])
30
+ * math.rotate([11, 12], math.pi / 2) // returns [-12, 11]
31
+ * math.rotate(matrix([11, 12]), math.pi / 2) // returns [-12, 11]
32
32
  *
33
- * math.rotate([1, 0, 0], unit('90deg'), [0, 0, 1]) // returns matrix([0, 1, 0])
34
- * math.rotate(matrix([1, 0, 0]), unit('90deg'), [0, 0, 1]) // returns matrix([0, 1, 0])
33
+ * math.rotate([1, 0, 0], unit('90deg'), [0, 0, 1]) // returns [0, 1, 0]
34
+ * math.rotate(matrix([1, 0, 0]), unit('90deg'), [0, 0, 1]) // returns Matrix [0, 1, 0]
35
35
  *
36
- * math.rotate([1, 0], math.complex(1 + i)) // returns matrix([cos(1 + i) - sin(1 + i), sin(1 + i) + cos(1 + i)])
36
+ * math.rotate([1, 0], math.complex(1 + i)) // returns [cos(1 + i) - sin(1 + i), sin(1 + i) + cos(1 + i)]
37
37
  *
38
38
  * See also:
39
39
  *
@@ -105,14 +105,14 @@ var createFormat = /* #__PURE__ */(0, _factory.factory)(name, dependencies, func
105
105
  * Examples:
106
106
  *
107
107
  * math.format(6.4) // returns '6.4'
108
- * math.format(1240000) // returns '1.24e6'
108
+ * math.format(1240000) // returns '1.24e+6'
109
109
  * math.format(1/3) // returns '0.3333333333333333'
110
110
  * math.format(1/3, 3) // returns '0.333'
111
111
  * math.format(21385, 2) // returns '21000'
112
112
  * math.format(12e8, {notation: 'fixed'}) // returns '1200000000'
113
113
  * math.format(2.3, {notation: 'fixed', precision: 4}) // returns '2.3000'
114
114
  * math.format(52.8, {notation: 'exponential'}) // returns '5.28e+1'
115
- * math.format(12400,{notation: 'engineering'}) // returns '12.400e+3'
115
+ * math.format(12400, {notation: 'engineering'}) // returns '12.4e+3'
116
116
  * math.format(2000, {lowerExp: -2, upperExp: 2}) // returns '2e+3'
117
117
  *
118
118
  * function formatCurrency(value) {
@@ -18,8 +18,7 @@ var dependencies = ['typed', 'format'];
18
18
  *
19
19
  * Examples:
20
20
  *
21
- * //the following outputs "0xF0"
22
- * math.hex(240)
21
+ * math.hex(240) // returns "0xF0"
23
22
  *
24
23
  * See also:
25
24
  *
@@ -27,11 +27,10 @@ var createAcot = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
27
27
  *
28
28
  * Examples:
29
29
  *
30
- * math.acot(0.5) // returns number 0.4636476090008061
30
+ * math.acot(0.5) // returns number 1.1071487177940904
31
+ * math.acot(2) // returns number 0.4636476090008061
31
32
  * math.acot(math.cot(1.5)) // returns number 1.5
32
33
  *
33
- * math.acot(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
34
- *
35
34
  * See also:
36
35
  *
37
36
  * cot, atan
@@ -29,11 +29,10 @@ var createAcsc = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
29
29
  *
30
30
  * Examples:
31
31
  *
32
- * math.acsc(0.5) // returns number 0.5235987755982989
32
+ * math.acsc(2) // returns 0.5235987755982989
33
+ * math.acsc(0.5) // returns Complex 1.5707963267948966 -1.3169578969248166i
33
34
  * math.acsc(math.csc(1.5)) // returns number ~1.5
34
35
  *
35
- * math.acsc(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
36
- *
37
36
  * See also:
38
37
  *
39
38
  * csc, asin, asec
@@ -29,10 +29,10 @@ var createAsec = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
29
29
  *
30
30
  * Examples:
31
31
  *
32
- * math.asec(0.5) // returns 1.0471975511965979
32
+ * math.asec(2) // returns 1.0471975511965979
33
33
  * math.asec(math.sec(1.5)) // returns 1.5
34
34
  *
35
- * math.asec(2) // returns 0 + 1.3169578969248166 i
35
+ * math.asec(0.5) // returns Complex 0 + 1.3169578969248166i
36
36
  *
37
37
  * See also:
38
38
  *
@@ -29,7 +29,7 @@ var createAsin = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
29
29
  * math.asin(0.5) // returns number 0.5235987755982989
30
30
  * math.asin(math.sin(1.5)) // returns number ~1.5
31
31
  *
32
- * math.asin(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
32
+ * math.asin(2) // returns Complex 1.5707963267948966 -1.3169578969248166i
33
33
  *
34
34
  * See also:
35
35
  *
@@ -25,10 +25,9 @@ var createAtan = /* #__PURE__ */(0, _factory.factory)(name, dependencies, functi
25
25
  * Examples:
26
26
  *
27
27
  * math.atan(0.5) // returns number 0.4636476090008061
28
+ * math.atan(2) // returns number 1.1071487177940904
28
29
  * math.atan(math.tan(1.5)) // returns number 1.5
29
30
  *
30
- * math.atan(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
31
- *
32
31
  * See also:
33
32
  *
34
33
  * tan, asin, acos
@@ -69,7 +69,7 @@ var createAtan2 = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
69
69
  * const x = math.cos(angle)
70
70
  * const y = math.sin(angle)
71
71
  *
72
- * math.atan(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
72
+ * math.atan(2) // returns number 1.1071487177940904
73
73
  *
74
74
  * See also:
75
75
  *
@@ -24,7 +24,7 @@ var createClone = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
24
24
  * Examples:
25
25
  *
26
26
  * math.clone(3.5) // returns number 3.5
27
- * math.clone(math.complex('2-4i') // returns Complex 2 - 4i
27
+ * math.clone(math.complex('2-4i')) // returns Complex 2 - 4i
28
28
  * math.clone(math.unit(45, 'deg')) // returns Unit 45 deg
29
29
  * math.clone([[1, 2], [3, 4]]) // returns Array [[1, 2], [3, 4]]
30
30
  * math.clone("hello world") // returns string "hello world"
@@ -30,7 +30,7 @@ var createHasNumericValue = /* #__PURE__ */(0, _factory.factory)(name, dependenc
30
30
  * math.hasNumericValue(0) // returns true
31
31
  * math.hasNumericValue(math.bignumber(500)) // returns true
32
32
  * math.hasNumericValue(math.fraction(4)) // returns true
33
- * math.hasNumericValue(math.complex('2-4i') // returns false
33
+ * math.hasNumericValue(math.complex('2-4i')) // returns false
34
34
  * math.hasNumericValue(false) // returns true
35
35
  * math.hasNumericValue([2.3, 'foo', false]) // returns [true, false, true]
36
36
  *
@@ -35,7 +35,7 @@ var createIsInteger = /* #__PURE__ */(0, _factory.factory)(name, dependencies, f
35
35
  * math.isInteger(math.fraction(4)) // returns true
36
36
  * math.isInteger('3') // returns true
37
37
  * math.isInteger([3, 0.5, -2]) // returns [true, false, true]
38
- * math.isInteger(math.complex('2-4i') // throws an error
38
+ * math.isInteger(math.complex('2-4i')) // throws an error
39
39
  *
40
40
  * See also:
41
41
  *
@@ -35,7 +35,7 @@ var createIsNaN = /* #__PURE__ */(0, _factory.factory)(name, dependencies, funct
35
35
  * math.isNaN(math.bignumber(0)) // returns false
36
36
  * math.isNaN(math.fraction(-2, 5)) // returns false
37
37
  * math.isNaN('-2') // returns false
38
- * math.isNaN([2, 0, -3, NaN]') // returns [false, false, false, true]
38
+ * math.isNaN([2, 0, -3, NaN]) // returns [false, false, false, true]
39
39
  *
40
40
  * See also:
41
41
  *
@@ -35,7 +35,7 @@ var createIsNegative = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
35
35
  * math.isNegative(math.bignumber(2)) // returns false
36
36
  * math.isNegative(math.fraction(-2, 5)) // returns true
37
37
  * math.isNegative('-2') // returns true
38
- * math.isNegative([2, 0, -3]') // returns [false, false, true]
38
+ * math.isNegative([2, 0, -3]) // returns [false, false, true]
39
39
  *
40
40
  * See also:
41
41
  *
@@ -31,7 +31,7 @@ var createIsNumeric = /* #__PURE__ */(0, _factory.factory)(name, dependencies, f
31
31
  * math.isNumeric(0) // returns true
32
32
  * math.isNumeric(math.bignumber(500)) // returns true
33
33
  * math.isNumeric(math.fraction(4)) // returns true
34
- * math.isNumeric(math.complex('2-4i') // returns false
34
+ * math.isNumeric(math.complex('2-4i')) // returns false
35
35
  * math.isNumeric([2.3, 'foo', false]) // returns [true, false, true]
36
36
  *
37
37
  * See also:
@@ -35,7 +35,7 @@ var createIsPositive = /* #__PURE__ */(0, _factory.factory)(name, dependencies,
35
35
  * math.isPositive(0.5) // returns true
36
36
  * math.isPositive(math.bignumber(2)) // returns true
37
37
  * math.isPositive(math.fraction(-2, 5)) // returns false
38
- * math.isPositive(math.fraction(1,3)) // returns false
38
+ * math.isPositive(math.fraction(1, 3)) // returns true
39
39
  * math.isPositive('2') // returns true
40
40
  * math.isPositive([2, 0, -3]) // returns [true, false, false]
41
41
  *
@@ -29,17 +29,17 @@ var createIsZero = /* #__PURE__ */(0, _factory.factory)(name, dependencies, func
29
29
  *
30
30
  * Examples:
31
31
  *
32
- * math.isZero(0) // returns true
33
- * math.isZero(2) // returns false
34
- * math.isZero(0.5) // returns false
35
- * math.isZero(math.bignumber(0)) // returns true
36
- * math.isZero(math.fraction(0)) // returns true
37
- * math.isZero(math.fraction(1,3)) // returns false
38
- * math.isZero(math.complex('2 - 4i') // returns false
39
- * math.isZero(math.complex('0i') // returns true
40
- * math.isZero('0') // returns true
41
- * math.isZero('2') // returns false
42
- * math.isZero([2, 0, -3]') // returns [false, true, false]
32
+ * math.isZero(0) // returns true
33
+ * math.isZero(2) // returns false
34
+ * math.isZero(0.5) // returns false
35
+ * math.isZero(math.bignumber(0)) // returns true
36
+ * math.isZero(math.fraction(0)) // returns true
37
+ * math.isZero(math.fraction(1,3)) // returns false
38
+ * math.isZero(math.complex('2 - 4i')) // returns false
39
+ * math.isZero(math.complex('0i')) // returns true
40
+ * math.isZero('0') // returns true
41
+ * math.isZero('2') // returns false
42
+ * math.isZero([2, 0, -3]) // returns [false, true, false]
43
43
  *
44
44
  * See also:
45
45
  *
package/lib/cjs/header.js CHANGED
@@ -6,8 +6,8 @@
6
6
  * It features real and complex numbers, units, matrices, a large set of
7
7
  * mathematical functions, and a flexible expression parser.
8
8
  *
9
- * @version 11.0.0
10
- * @date 2022-07-23
9
+ * @version 11.2.0
10
+ * @date 2022-09-12
11
11
  *
12
12
  * @license
13
13
  * Copyright (C) 2013-2022 Jos de Jong <wjosdejong@gmail.com>
@@ -9,10 +9,10 @@ exports.createUnitClass = void 0;
9
9
 
10
10
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
11
 
12
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
-
14
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
13
 
14
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
+
16
16
  var _is = require("../../utils/is.js");
17
17
 
18
18
  var _factory = require("../../utils/factory.js");
@@ -53,8 +53,8 @@ var createUnitClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, f
53
53
  /**
54
54
  * A unit can be constructed in the following ways:
55
55
  *
56
- * const a = new Unit(value, name)
57
- * const b = new Unit(null, name)
56
+ * const a = new Unit(value, valuelessUnit)
57
+ * const b = new Unit(null, valuelessUnit)
58
58
  * const c = Unit.parse(str)
59
59
  *
60
60
  * Example usage:
@@ -67,10 +67,10 @@ var createUnitClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, f
67
67
  * @class Unit
68
68
  * @constructor Unit
69
69
  * @param {number | BigNumber | Fraction | Complex | boolean} [value] A value like 5.2
70
- * @param {string} [name] A unit name like "cm" or "inch", or a derived unit of the form: "u1[^ex1] [u2[^ex2] ...] [/ u3[^ex3] [u4[^ex4]]]", such as "kg m^2/s^2", where each unit appearing after the forward slash is taken to be in the denominator. "kg m^2 s^-2" is a synonym and is also acceptable. Any of the units can include a prefix.
70
+ * @param {string | Unit} valuelessUnit A unit without value. Can have prefix, like "cm"
71
71
  */
72
72
 
73
- function Unit(value, name) {
73
+ function Unit(value, valuelessUnit) {
74
74
  if (!(this instanceof Unit)) {
75
75
  throw new Error('Constructor must be called with the new operator');
76
76
  }
@@ -79,31 +79,36 @@ var createUnitClass = /* #__PURE__ */(0, _factory.factory)(name, dependencies, f
79
79
  throw new TypeError('First parameter in Unit constructor must be number, BigNumber, Fraction, Complex, or undefined');
80
80
  }
81
81
 
82
- if (name !== undefined && (typeof name !== 'string' || name === '')) {
83
- throw new TypeError('Second parameter in Unit constructor must be a string');
84
- }
85
-
86
- if (name !== undefined) {
87
- var u = Unit.parse(name);
88
- this.units = u.units;
89
- this.dimensions = u.dimensions;
90
- } else {
91
- this.units = [];
92
- this.dimensions = [];
93
-
94
- for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
95
- this.dimensions[i] = 0;
96
- }
97
- }
98
-
99
- this.value = value !== undefined && value !== null ? this._normalize(value) : null;
100
82
  this.fixPrefix = false; // if true, function format will not search for the
101
83
  // best prefix but leave it as initially provided.
102
84
  // fixPrefix is set true by the method Unit.to
103
85
  // The justification behind this is that if the constructor is explicitly called,
104
- // the caller wishes the units to be returned exactly as he supplied.
86
+ // the caller wishes the units to be returned exactly as supplied.
105
87
 
106
88
  this.skipAutomaticSimplification = true;
89
+
90
+ if (valuelessUnit === undefined) {
91
+ this.units = [];
92
+ this.dimensions = BASE_DIMENSIONS.map(function (x) {
93
+ return 0;
94
+ });
95
+ } else if (typeof valuelessUnit === 'string') {
96
+ var u = Unit.parse(valuelessUnit);
97
+ this.units = u.units;
98
+ this.dimensions = u.dimensions;
99
+ } else if ((0, _is.isUnit)(valuelessUnit) && valuelessUnit.value === null) {
100
+ // clone from valuelessUnit
101
+ this.fixPrefix = valuelessUnit.fixPrefix;
102
+ this.skipAutomaticSimplification = valuelessUnit.skipAutomaticSimplification;
103
+ this.dimensions = valuelessUnit.dimensions.slice(0);
104
+ this.units = valuelessUnit.units.map(function (u) {
105
+ return (0, _extends2["default"])({}, u);
106
+ });
107
+ } else {
108
+ throw new TypeError('Second parameter in Unit constructor must be a string or valueless Unit');
109
+ }
110
+
111
+ this.value = this._normalize(value);
107
112
  }
108
113
  /**
109
114
  * Attach type information
@@ -24,10 +24,13 @@ var createUnitFunction = /* #__PURE__ */(0, _factory.factory)(name, dependencies
24
24
  * Syntax:
25
25
  *
26
26
  * math.unit(unit : string)
27
- * math.unit(value : number, unit : string)
27
+ * math.unit(value : number, valuelessUnit : Unit)
28
+ * math.unit(value : number, valuelessUnit : string)
28
29
  *
29
30
  * Examples:
30
31
  *
32
+ * const kph = math.unit('km/h') // returns Unit km/h (valueless)
33
+ * const v = math.unit(25, kph) // returns Unit 25 km/h
31
34
  * const a = math.unit(5, 'cm') // returns Unit 50 mm
32
35
  * const b = math.unit('23 kg') // returns Unit 23 kg
33
36
  * a.to('m') // returns Unit 0.05 m
@@ -52,7 +55,7 @@ var createUnitFunction = /* #__PURE__ */(0, _factory.factory)(name, dependencies
52
55
  allowNoUnits: true
53
56
  }); // a unit with value, like '5cm'
54
57
  },
55
- 'number | BigNumber | Fraction | Complex, string': function numberBigNumberFractionComplexString(value, unit) {
58
+ 'number | BigNumber | Fraction | Complex, string | Unit': function numberBigNumberFractionComplexStringUnit(value, unit) {
56
59
  return new Unit(value, unit);
57
60
  },
58
61
  'number | BigNumber | Fraction': function numberBigNumberFraction(value) {
@@ -37,6 +37,7 @@ exports.isParenthesisNode = isParenthesisNode;
37
37
  exports.isRange = isRange;
38
38
  exports.isRangeNode = isRangeNode;
39
39
  exports.isRegExp = isRegExp;
40
+ exports.isRelationalNode = isRelationalNode;
40
41
  exports.isResultSet = isResultSet;
41
42
  exports.isSparseMatrix = isSparseMatrix;
42
43
  exports.isString = isString;
@@ -237,6 +238,10 @@ function isRangeNode(x) {
237
238
  return x && x.isRangeNode === true && x.constructor.prototype.isNode === true || false;
238
239
  }
239
240
 
241
+ function isRelationalNode(x) {
242
+ return x && x.isRelationalNode === true && x.constructor.prototype.isNode === true || false;
243
+ }
244
+
240
245
  function isSymbolNode(x) {
241
246
  return x && x.isSymbolNode === true && x.constructor.prototype.isNode === true || false;
242
247
  }
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.version = void 0;
7
- var version = '11.0.0'; // Note: This file is automatically generated when building math.js.
7
+ var version = '11.2.0'; // Note: This file is automatically generated when building math.js.
8
8
  // Changes made in this file will be overwritten.
9
9
 
10
10
  exports.version = version;
@@ -5,7 +5,7 @@ import * as emitter from './../utils/emitter.js';
5
5
  import { importFactory } from './function/import.js';
6
6
  import { configFactory } from './function/config.js';
7
7
  import { factory, isFactory } from '../utils/factory.js';
8
- import { isAccessorNode, isArray, isArrayNode, isAssignmentNode, isBigNumber, isBlockNode, isBoolean, isChain, isCollection, isComplex, isConditionalNode, isConstantNode, isDate, isDenseMatrix, isFraction, isFunction, isFunctionAssignmentNode, isFunctionNode, isHelp, isIndex, isIndexNode, isMatrix, isNode, isNull, isNumber, isObject, isObjectNode, isOperatorNode, isParenthesisNode, isRange, isRangeNode, isRegExp, isResultSet, isSparseMatrix, isString, isSymbolNode, isUndefined, isUnit } from '../utils/is.js';
8
+ import { isAccessorNode, isArray, isArrayNode, isAssignmentNode, isBigNumber, isBlockNode, isBoolean, isChain, isCollection, isComplex, isConditionalNode, isConstantNode, isDate, isDenseMatrix, isFraction, isFunction, isFunctionAssignmentNode, isFunctionNode, isHelp, isIndex, isIndexNode, isMatrix, isNode, isNull, isNumber, isObject, isObjectNode, isOperatorNode, isParenthesisNode, isRange, isRangeNode, isRelationalNode, isRegExp, isResultSet, isSparseMatrix, isString, isSymbolNode, isUndefined, isUnit } from '../utils/is.js';
9
9
  import { ArgumentsError } from '../error/ArgumentsError.js';
10
10
  import { DimensionError } from '../error/DimensionError.js';
11
11
  import { IndexError } from '../error/IndexError.js';
@@ -97,6 +97,7 @@ export function create(factories, config) {
97
97
  isOperatorNode,
98
98
  isParenthesisNode,
99
99
  isRangeNode,
100
+ isRelationalNode,
100
101
  isSymbolNode,
101
102
  isChain
102
103
  }); // load config function and apply provided config