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 +9 -0
- package/docs/expressions/syntax.md +46 -43
- package/docs/reference/functions/setCartesian.md +3 -1
- package/lib/browser/math.js +3 -3
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesParserClass.generated.js +2 -2
- package/lib/cjs/entry/dependenciesNumber/dependenciesParserClass.generated.js +2 -2
- package/lib/cjs/entry/impureFunctionsAny.generated.js +1 -1
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +1 -1
- package/lib/cjs/expression/Parser.js +5 -4
- package/lib/cjs/expression/embeddedDocs/function/set/setCartesian.js +1 -1
- package/lib/cjs/expression/node/OperatorNode.js +9 -6
- package/lib/cjs/expression/parse.js +42 -6
- package/lib/cjs/function/set/setCartesian.js +3 -1
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesParserClass.generated.js +2 -2
- package/lib/esm/entry/dependenciesNumber/dependenciesParserClass.generated.js +2 -2
- package/lib/esm/entry/impureFunctionsAny.generated.js +1 -1
- package/lib/esm/entry/impureFunctionsNumber.generated.js +1 -1
- package/lib/esm/expression/Parser.js +5 -4
- package/lib/esm/expression/embeddedDocs/function/set/setCartesian.js +1 -1
- package/lib/esm/expression/node/OperatorNode.js +9 -6
- package/lib/esm/expression/parse.js +42 -6
- package/lib/esm/function/set/setCartesian.js +3 -1
- package/lib/esm/version.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +8 -8
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
|
49
|
-
----------- |
|
50
|
-
`(`, `)` | Grouping
|
51
|
-
`[`, `]` | Matrix, Index
|
52
|
-
`{`, `}` | Object
|
53
|
-
`,` | Parameter separator
|
54
|
-
`.` | Property accessor
|
55
|
-
`;` | Statement separator
|
56
|
-
`;` | Row separator
|
57
|
-
`\n` | Statement separator
|
58
|
-
`+` | Add
|
59
|
-
`+` | Unary plus
|
60
|
-
`-` | Subtract
|
61
|
-
`-` | Unary minus
|
62
|
-
`*` | Multiply
|
63
|
-
`.*` | Element-wise multiply
|
64
|
-
`/` | Divide
|
65
|
-
`./` | Element-wise divide
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
`
|
70
|
-
|
71
|
-
|
72
|
-
|
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>|</code> | Bitwise or | <code>x | y</code> | Left to right | <code>5 | 3</code> | `7`
|
74
77
|
<code>^|</code> | Bitwise xor | <code>x ^| y</code> | Left to right | <code>5 ^| 2</code> | `7`
|
75
|
-
`<<` | Left shift
|
76
|
-
`>>` | Right arithmetic shift
|
77
|
-
`>>>` | Right logical shift
|
78
|
-
`and` | Logical and
|
79
|
-
`not` | Logical not
|
80
|
-
`or` | Logical or
|
81
|
-
`xor` | Logical xor
|
82
|
-
`=` | Assignment
|
83
|
-
`?` `:` | Conditional expression
|
84
|
-
`:` | Range
|
85
|
-
`to`, `in` | Unit conversion
|
86
|
-
`==` | Equal
|
87
|
-
`!=` | Unequal
|
88
|
-
`<` | Smaller
|
89
|
-
`>` | Larger
|
90
|
-
`<=` | Smallereq
|
91
|
-
`>=` | Largereq
|
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
|
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 | 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
|
|