mathjs 9.4.5 → 9.5.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.
package/HISTORY.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # History
2
2
 
3
+ # 2021-09-22, version 9.5.0
4
+
5
+ - Implemented support for calculations with percentage, see #2303.
6
+ Thanks @rvramesh.
7
+ - Fix #2319: make the API of `Parser.evaluate` consistent with `math.evaluate`:
8
+ support a list with expressions as input.
9
+ - Improved documentation of function `setCartesian`. Thanks @fieldfoxWim.
10
+
11
+
3
12
  # 2021-09-15, version 9.4.5
4
13
 
5
14
  - Improved the performance of `Node.equals` by improving the internal
@@ -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
@@ -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