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.
- package/HISTORY.md +35 -0
- package/bin/cli.js +0 -0
- package/docs/expressions/syntax.md +46 -43
- package/docs/reference/functions/format.md +5 -2
- package/docs/reference/functions/parser.md +4 -4
- package/docs/reference/functions/setCartesian.md +3 -1
- package/lib/browser/math.js +5 -5
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/constants.js +1 -1
- package/lib/cjs/core/function/config.js +1 -1
- package/lib/cjs/core/function/import.js +2 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesParserClass.generated.js +2 -2
- package/lib/cjs/entry/dependenciesAny.generated.js +999 -999
- package/lib/cjs/entry/dependenciesNumber/dependenciesParserClass.generated.js +2 -2
- package/lib/cjs/entry/dependenciesNumber.generated.js +581 -581
- package/lib/cjs/entry/impureFunctionsAny.generated.js +314 -313
- package/lib/cjs/entry/impureFunctionsNumber.generated.js +223 -222
- package/lib/cjs/entry/mainAny.js +8 -8
- package/lib/cjs/entry/mainNumber.js +8 -8
- package/lib/cjs/entry/pureFunctionsAny.generated.js +1100 -1100
- package/lib/cjs/entry/pureFunctionsNumber.generated.js +375 -375
- package/lib/cjs/entry/typeChecks.js +12 -12
- package/lib/cjs/expression/Parser.js +6 -5
- package/lib/cjs/expression/embeddedDocs/function/set/setCartesian.js +1 -1
- package/lib/cjs/expression/function/parser.js +4 -4
- package/lib/cjs/expression/node/OperatorNode.js +9 -6
- package/lib/cjs/expression/operators.js +1 -1
- package/lib/cjs/expression/parse.js +42 -6
- package/lib/cjs/factoriesAny.js +660 -660
- package/lib/cjs/factoriesNumber.js +268 -237
- package/lib/cjs/function/set/setCartesian.js +3 -1
- package/lib/cjs/function/string/format.js +5 -2
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/plain/bignumber/arithmetic.js +2 -2
- package/lib/cjs/plain/number/arithmetic.js +10 -10
- package/lib/cjs/plain/number/constants.js +1 -1
- package/lib/cjs/plain/number/logical.js +1 -1
- package/lib/cjs/plain/number/probability.js +2 -1
- package/lib/cjs/plain/number/trigonometry.js +1 -1
- package/lib/cjs/plain/number/utils.js +1 -1
- package/lib/cjs/type/unit/physicalConstants.js +1 -1
- package/lib/cjs/utils/array.js +14 -14
- package/lib/cjs/utils/bignumber/bitwise.js +1 -1
- package/lib/cjs/utils/customs.js +5 -5
- package/lib/cjs/utils/factory.js +3 -3
- package/lib/cjs/utils/function.js +1 -1
- package/lib/cjs/utils/is.js +23 -23
- package/lib/cjs/utils/latex.js +2 -1
- package/lib/cjs/utils/map.js +3 -3
- package/lib/cjs/utils/noop.js +1 -1
- package/lib/cjs/utils/number.js +10 -6
- package/lib/cjs/utils/object.js +8 -8
- package/lib/cjs/utils/snapshot.js +1 -1
- package/lib/cjs/utils/string.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/core/function/import.js +2 -1
- package/lib/esm/entry/dependenciesAny/dependenciesParserClass.generated.js +2 -2
- package/lib/esm/entry/dependenciesAny.generated.js +270 -270
- package/lib/esm/entry/dependenciesNumber/dependenciesParserClass.generated.js +2 -2
- package/lib/esm/entry/dependenciesNumber.generated.js +163 -163
- package/lib/esm/entry/impureFunctionsAny.generated.js +301 -301
- package/lib/esm/entry/impureFunctionsNumber.generated.js +211 -211
- package/lib/esm/entry/pureFunctionsAny.generated.js +816 -816
- package/lib/esm/entry/pureFunctionsNumber.generated.js +234 -234
- package/lib/esm/expression/Parser.js +6 -5
- package/lib/esm/expression/embeddedDocs/function/set/setCartesian.js +1 -1
- package/lib/esm/expression/function/parser.js +4 -4
- 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/function/string/format.js +5 -2
- package/lib/esm/version.js +1 -1
- package/package.json +16 -16
- 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
|
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
|
@@ -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
|
-
|
53
|
-
|
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')
|
40
|
-
parser.evaluate('x + 3')
|
41
|
-
parser.evaluate('
|
42
|
-
parser.evaluate('f(2, 3)')
|
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
|
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
|
|