mathjs 9.4.5 → 10.0.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 (74) hide show
  1. package/HISTORY.md +35 -0
  2. package/bin/cli.js +0 -0
  3. package/docs/expressions/syntax.md +46 -43
  4. package/docs/reference/functions/format.md +5 -2
  5. package/docs/reference/functions/parser.md +4 -4
  6. package/docs/reference/functions/setCartesian.md +3 -1
  7. package/lib/browser/math.js +5 -5
  8. package/lib/browser/math.js.map +1 -1
  9. package/lib/cjs/constants.js +1 -1
  10. package/lib/cjs/core/function/config.js +1 -1
  11. package/lib/cjs/core/function/import.js +2 -1
  12. package/lib/cjs/entry/dependenciesAny/dependenciesParserClass.generated.js +2 -2
  13. package/lib/cjs/entry/dependenciesAny.generated.js +999 -999
  14. package/lib/cjs/entry/dependenciesNumber/dependenciesParserClass.generated.js +2 -2
  15. package/lib/cjs/entry/dependenciesNumber.generated.js +581 -581
  16. package/lib/cjs/entry/impureFunctionsAny.generated.js +314 -313
  17. package/lib/cjs/entry/impureFunctionsNumber.generated.js +223 -222
  18. package/lib/cjs/entry/mainAny.js +8 -8
  19. package/lib/cjs/entry/mainNumber.js +8 -8
  20. package/lib/cjs/entry/pureFunctionsAny.generated.js +1100 -1100
  21. package/lib/cjs/entry/pureFunctionsNumber.generated.js +375 -375
  22. package/lib/cjs/entry/typeChecks.js +12 -12
  23. package/lib/cjs/expression/Parser.js +6 -5
  24. package/lib/cjs/expression/embeddedDocs/function/set/setCartesian.js +1 -1
  25. package/lib/cjs/expression/function/parser.js +4 -4
  26. package/lib/cjs/expression/node/OperatorNode.js +9 -6
  27. package/lib/cjs/expression/operators.js +1 -1
  28. package/lib/cjs/expression/parse.js +42 -6
  29. package/lib/cjs/factoriesAny.js +660 -660
  30. package/lib/cjs/factoriesNumber.js +268 -237
  31. package/lib/cjs/function/set/setCartesian.js +3 -1
  32. package/lib/cjs/function/string/format.js +5 -2
  33. package/lib/cjs/header.js +2 -2
  34. package/lib/cjs/plain/bignumber/arithmetic.js +2 -2
  35. package/lib/cjs/plain/number/arithmetic.js +10 -10
  36. package/lib/cjs/plain/number/constants.js +1 -1
  37. package/lib/cjs/plain/number/logical.js +1 -1
  38. package/lib/cjs/plain/number/probability.js +2 -1
  39. package/lib/cjs/plain/number/trigonometry.js +1 -1
  40. package/lib/cjs/plain/number/utils.js +1 -1
  41. package/lib/cjs/type/unit/physicalConstants.js +1 -1
  42. package/lib/cjs/utils/array.js +14 -14
  43. package/lib/cjs/utils/bignumber/bitwise.js +1 -1
  44. package/lib/cjs/utils/customs.js +5 -5
  45. package/lib/cjs/utils/factory.js +3 -3
  46. package/lib/cjs/utils/function.js +1 -1
  47. package/lib/cjs/utils/is.js +23 -23
  48. package/lib/cjs/utils/latex.js +2 -1
  49. package/lib/cjs/utils/map.js +3 -3
  50. package/lib/cjs/utils/noop.js +1 -1
  51. package/lib/cjs/utils/number.js +10 -6
  52. package/lib/cjs/utils/object.js +8 -8
  53. package/lib/cjs/utils/snapshot.js +1 -1
  54. package/lib/cjs/utils/string.js +2 -2
  55. package/lib/cjs/version.js +1 -1
  56. package/lib/esm/core/function/import.js +2 -1
  57. package/lib/esm/entry/dependenciesAny/dependenciesParserClass.generated.js +2 -2
  58. package/lib/esm/entry/dependenciesAny.generated.js +270 -270
  59. package/lib/esm/entry/dependenciesNumber/dependenciesParserClass.generated.js +2 -2
  60. package/lib/esm/entry/dependenciesNumber.generated.js +163 -163
  61. package/lib/esm/entry/impureFunctionsAny.generated.js +301 -301
  62. package/lib/esm/entry/impureFunctionsNumber.generated.js +211 -211
  63. package/lib/esm/entry/pureFunctionsAny.generated.js +816 -816
  64. package/lib/esm/entry/pureFunctionsNumber.generated.js +234 -234
  65. package/lib/esm/expression/Parser.js +6 -5
  66. package/lib/esm/expression/embeddedDocs/function/set/setCartesian.js +1 -1
  67. package/lib/esm/expression/function/parser.js +4 -4
  68. package/lib/esm/expression/node/OperatorNode.js +9 -6
  69. package/lib/esm/expression/parse.js +42 -6
  70. package/lib/esm/function/set/setCartesian.js +3 -1
  71. package/lib/esm/function/string/format.js +5 -2
  72. package/lib/esm/version.js +1 -1
  73. package/package.json +16 -16
  74. package/types/index.d.ts +281 -77
package/HISTORY.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # History
2
2
 
3
+ # 2021-11-03, version 10.0.0
4
+
5
+ !!! BE CAREFUL: BREAKING CHANGES IN THE TYPESCRIPT DEFINITIONS !!!
6
+
7
+ - Improvements to the Typescript typings (commit fc5c202e).
8
+ Thanks @joshhansen. First introduced in v9.5.1, but reverted because
9
+ it contains breaking changes.
10
+
11
+ Breaking changes: interface `MathNode` is now renamed to `MathNodeCommon`
12
+ and the related interfaces are structured in a different way.
13
+
14
+ - Fixed a typo in the TypeScript definition of toHTML. Thanks @TheToto.
15
+
16
+
17
+ # 2021-11-03, version 9.5.2`
18
+
19
+ - Revert the improvements to the Typescript typings because they contain
20
+ breaking changes. The improvements will be published in v10.0.0. See #2339.
21
+
22
+
23
+ # 2021-10-13, version 9.5.1
24
+
25
+ - Various improvements to the Typescript typings.
26
+ Thanks @joshhansen and @DianaTdr.
27
+
28
+
29
+ # 2021-09-22, version 9.5.0
30
+
31
+ - Implemented support for calculations with percentage, see #2303.
32
+ Thanks @rvramesh.
33
+ - Fix #2319: make the API of `Parser.evaluate` consistent with `math.evaluate`:
34
+ support a list with expressions as input.
35
+ - Improved documentation of function `setCartesian`. Thanks @fieldfoxWim.
36
+
37
+
3
38
  # 2021-09-15, version 9.4.5
4
39
 
5
40
  - Improved the performance of `Node.equals` by improving the internal
package/bin/cli.js CHANGED
File without changes
@@ -45,50 +45,53 @@ math.evaluate('(2 + 3) * 4') // 20
45
45
 
46
46
  The following operators are available:
47
47
 
48
- Operator | Name | Syntax | Associativity | Example | Result
49
- ----------- | ----------------------- | ---------- | ------------- | --------------------- | ---------------
50
- `(`, `)` | Grouping | `(x)` | None | `2 * (3 + 4)` | `14`
51
- `[`, `]` | Matrix, Index | `[...]` | None | `[[1,2],[3,4]]` | `[[1,2],[3,4]]`
52
- `{`, `}` | Object | `{...}` | None | `{a: 1, b: 2}` | `{a: 1, b: 2}`
53
- `,` | Parameter separator | `x, y` | Left to right | `max(2, 1, 5)` | `5`
54
- `.` | Property accessor | `obj.prop` | Left to right | `obj={a: 12}; obj.a` | `12`
55
- `;` | Statement separator | `x; y` | Left to right | `a=2; b=3; a*b` | `[6]`
56
- `;` | Row separator | `[x; y]` | Left to right | `[1,2;3,4]` | `[[1,2],[3,4]]`
57
- `\n` | Statement separator | `x \n y` | Left to right | `a=2 \n b=3 \n a*b` | `[2,3,6]`
58
- `+` | Add | `x + y` | Left to right | `4 + 5` | `9`
59
- `+` | Unary plus | `+y` | Right to left | `+4` | `4`
60
- `-` | Subtract | `x - y` | Left to right | `7 - 3` | `4`
61
- `-` | Unary minus | `-y` | Right to left | `-4` | `-4`
62
- `*` | Multiply | `x * y` | Left to right | `2 * 3` | `6`
63
- `.*` | Element-wise multiply | `x .* y` | Left to right | `[1,2,3] .* [1,2,3]` | `[1,4,9]`
64
- `/` | Divide | `x / y` | Left to right | `6 / 2` | `3`
65
- `./` | Element-wise divide | `x ./ y` | Left to right | `[9,6,4] ./ [3,2,2]` | `[3,3,2]`
66
- `%`, `mod` | Modulus | `x % y` | Left to right | `8 % 3` | `2`
67
- `^` | Power | `x ^ y` | Right to left | `2 ^ 3` | `8`
68
- `.^` | Element-wise power | `x .^ y` | Right to left | `[2,3] .^ [3,3]` | `[8,27]`
69
- `'` | Transpose | `y'` | Left to right | `[[1,2],[3,4]]'` | `[[1,3],[2,4]]`
70
- `!` | Factorial | `y!` | Left to right | `5!` | `120`
71
- `&` | Bitwise and | `x & y` | Left to right | `5 & 3` | `1`
72
- `~` | Bitwise not | `~x` | Right to left | `~2` | `-3`
48
+ Operator | Name | Syntax | Associativity | Example | Result
49
+ ----------- | -------------------------- | ---------- | ------------- | --------------------- | ---------------
50
+ `(`, `)` | Grouping | `(x)` | None | `2 * (3 + 4)` | `14`
51
+ `[`, `]` | Matrix, Index | `[...]` | None | `[[1,2],[3,4]]` | `[[1,2],[3,4]]`
52
+ `{`, `}` | Object | `{...}` | None | `{a: 1, b: 2}` | `{a: 1, b: 2}`
53
+ `,` | Parameter separator | `x, y` | Left to right | `max(2, 1, 5)` | `5`
54
+ `.` | Property accessor | `obj.prop` | Left to right | `obj={a: 12}; obj.a` | `12`
55
+ `;` | Statement separator | `x; y` | Left to right | `a=2; b=3; a*b` | `[6]`
56
+ `;` | Row separator | `[x; y]` | Left to right | `[1,2;3,4]` | `[[1,2],[3,4]]`
57
+ `\n` | Statement separator | `x \n y` | Left to right | `a=2 \n b=3 \n a*b` | `[2,3,6]`
58
+ `+` | Add | `x + y` | Left to right | `4 + 5` | `9`
59
+ `+` | Unary plus | `+y` | Right to left | `+4` | `4`
60
+ `-` | Subtract | `x - y` | Left to right | `7 - 3` | `4`
61
+ `-` | Unary minus | `-y` | Right to left | `-4` | `-4`
62
+ `*` | Multiply | `x * y` | Left to right | `2 * 3` | `6`
63
+ `.*` | Element-wise multiply | `x .* y` | Left to right | `[1,2,3] .* [1,2,3]` | `[1,4,9]`
64
+ `/` | Divide | `x / y` | Left to right | `6 / 2` | `3`
65
+ `./` | Element-wise divide | `x ./ y` | Left to right | `[9,6,4] ./ [3,2,2]` | `[3,3,2]`
66
+ `%` | Percentage | `x%` | None | `8%` | `0.08`
67
+ `%` | Addition with Percentage | `x + y%` | Left to right | `100 + 3%` | `103`
68
+ `%` | Subtraction with Percentage| `x - y%` | Left to right | `100 - 3%` | `97`
69
+ `%` `mod` | Modulus | `x % y` | Left to right | `8 % 3` | `2`
70
+ `^` | Power | `x ^ y` | Right to left | `2 ^ 3` | `8`
71
+ `.^` | Element-wise power | `x .^ y` | Right to left | `[2,3] .^ [3,3]` | `[8,27]`
72
+ `'` | Transpose | `y'` | Left to right | `[[1,2],[3,4]]'` | `[[1,3],[2,4]]`
73
+ `!` | Factorial | `y!` | Left to right | `5!` | `120`
74
+ `&` | Bitwise and | `x & y` | Left to right | `5 & 3` | `1`
75
+ `~` | Bitwise not | `~x` | Right to left | `~2` | `-3`
73
76
  <code>&#124;</code> | Bitwise or | <code>x &#124; y</code> | Left to right | <code>5 &#124; 3</code> | `7`
74
77
  <code>^&#124;</code> | Bitwise xor | <code>x ^&#124; y</code> | Left to right | <code>5 ^&#124; 2</code> | `7`
75
- `<<` | Left shift | `x << y` | Left to right | `4 << 1` | `8`
76
- `>>` | Right arithmetic shift | `x >> y` | Left to right | `8 >> 1` | `4`
77
- `>>>` | Right logical shift | `x >>> y` | Left to right | `-8 >>> 1` | `2147483644`
78
- `and` | Logical and | `x and y` | Left to right | `true and false` | `false`
79
- `not` | Logical not | `not y` | Right to left | `not true` | `false`
80
- `or` | Logical or | `x or y` | Left to right | `true or false` | `true`
81
- `xor` | Logical xor | `x xor y` | Left to right | `true xor true` | `false`
82
- `=` | Assignment | `x = y` | Right to left | `a = 5` | `5`
83
- `?` `:` | Conditional expression | `x ? y : z` | Right to left | `15 > 100 ? 1 : -1` | `-1`
84
- `:` | Range | `x : y` | Right to left | `1:4` | `[1,2,3,4]`
85
- `to`, `in` | Unit conversion | `x to y` | Left to right | `2 inch to cm` | `5.08 cm`
86
- `==` | Equal | `x == y` | Left to right | `2 == 4 - 2` | `true`
87
- `!=` | Unequal | `x != y` | Left to right | `2 != 3` | `true`
88
- `<` | Smaller | `x < y` | Left to right | `2 < 3` | `true`
89
- `>` | Larger | `x > y` | Left to right | `2 > 3` | `false`
90
- `<=` | Smallereq | `x <= y` | Left to right | `4 <= 3` | `false`
91
- `>=` | Largereq | `x >= y` | Left to right | `2 + 4 >= 6` | `true`
78
+ `<<` | Left shift | `x << y` | Left to right | `4 << 1` | `8`
79
+ `>>` | Right arithmetic shift | `x >> y` | Left to right | `8 >> 1` | `4`
80
+ `>>>` | Right logical shift | `x >>> y` | Left to right | `-8 >>> 1` | `2147483644`
81
+ `and` | Logical and | `x and y` | Left to right | `true and false` | `false`
82
+ `not` | Logical not | `not y` | Right to left | `not true` | `false`
83
+ `or` | Logical or | `x or y` | Left to right | `true or false` | `true`
84
+ `xor` | Logical xor | `x xor y` | Left to right | `true xor true` | `false`
85
+ `=` | Assignment | `x = y` | Right to left | `a = 5` | `5`
86
+ `?` `:` | Conditional expression | `x ? y : z` | Right to left | `15 > 100 ? 1 : -1` | `-1`
87
+ `:` | Range | `x : y` | Right to left | `1:4` | `[1,2,3,4]`
88
+ `to`, `in` | Unit conversion | `x to y` | Left to right | `2 inch to cm` | `5.08 cm`
89
+ `==` | Equal | `x == y` | Left to right | `2 == 4 - 2` | `true`
90
+ `!=` | Unequal | `x != y` | Left to right | `2 != 3` | `true`
91
+ `<` | Smaller | `x < y` | Left to right | `2 < 3` | `true`
92
+ `>` | Larger | `x > y` | Left to right | `2 > 3` | `false`
93
+ `<=` | Smallereq | `x <= y` | Left to right | `4 <= 3` | `false`
94
+ `>=` | Largereq | `x >= y` | Left to right | `2 + 4 >= 6` | `true`
92
95
 
93
96
 
94
97
  ## Precedence
@@ -104,7 +107,7 @@ Operators | Description
104
107
  `^`, `.^` | Exponentiation
105
108
  `+`, `-`, `~`, `not` | Unary plus, unary minus, bitwise not, logical not
106
109
  See section below | Implicit multiplication
107
- `*`, `/`, `.*`, `./`, `%`, `mod` | Multiply, divide, modulus
110
+ `*`, `/`, `.*`, `./`, `%`, `mod` | Multiply, divide, percentage, modulus
108
111
  `+`, `-` | Add, subtract
109
112
  `:` | Range
110
113
  `to`, `in` | Unit conversion
@@ -49,8 +49,11 @@ math.format(value, callback)
49
49
  For example format(-1, {notation: 'hex', wordSize: 8}) === '0xffi8'.
50
50
  Default value is undefined.
51
51
  - `precision: number`
52
- A number between 0 and 16 to round the digits of the number. In case
53
- of notations 'exponential', 'engineering', and 'auto', `precision`
52
+ Limit the number of digits of the formatted value.
53
+ For regular numbers, must be a number between 0 and 16.
54
+ For bignumbers, the maximum depends on the configured precision,
55
+ see function `config()`.
56
+ In case of notations 'exponential', 'engineering', and 'auto', `precision`
54
57
  defines the total number of significant digits returned.
55
58
  In case of notation 'fixed', `precision` defines the number of
56
59
  significant digits after the decimal point.
@@ -36,10 +36,10 @@ const c = parser.evaluate('2 inch in cm') // 5.08 cm
36
36
  const d = parser.evaluate('cos(45 deg)') // 0.7071067811865476
37
37
 
38
38
  // define variables and functions
39
- parser.evaluate('x = 7 / 2') // 3.5
40
- parser.evaluate('x + 3') // 6.5
41
- parser.evaluate('function f(x, y) = x^y') // f(x, y)
42
- parser.evaluate('f(2, 3)') // 8
39
+ parser.evaluate('x = 7 / 2') // 3.5
40
+ parser.evaluate('x + 3') // 6.5
41
+ parser.evaluate('f(x, y) = x^y') // f(x, y)
42
+ parser.evaluate('f(2, 3)') // 8
43
43
 
44
44
  // get and set variables and functions
45
45
  const x = parser.get('x') // 7
@@ -3,7 +3,8 @@
3
3
  # Function setCartesian
4
4
 
5
5
  Create the cartesian product of two (multi)sets.
6
- Multi-dimension arrays will be converted to single-dimension arrays before the operation.
6
+ Multi-dimension arrays will be converted to single-dimension arrays
7
+ and the values will be sorted in ascending order before the operation.
7
8
 
8
9
 
9
10
  ## Syntax
@@ -30,6 +31,7 @@ Array &#124; Matrix | The cartesian product of two (multi)sets
30
31
 
31
32
  ```js
32
33
  math.setCartesian([1, 2], [3, 4]) // returns [[1, 3], [1, 4], [2, 3], [2, 4]]
34
+ math.setCartesian([4, 3], [2, 1]) // returns [[3, 1], [3, 2], [4, 1], [4, 2]]
33
35
  ```
34
36
 
35
37