mathjs 5.0.0 → 5.0.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mathjs might be problematic. Click here for more details.
- package/HISTORY.md +48 -1
- package/README.md +2 -1
- package/dist/math.js +20114 -20090
- package/dist/math.min.js +7 -7
- package/dist/math.min.map +1 -1
- package/docs/core/configuration.md +1 -1
- package/docs/datatypes/numbers.md +1 -1
- package/docs/datatypes/units.md +1 -1
- package/docs/expressions/algebra.md +25 -1
- package/docs/getting_started.md +2 -2
- package/docs/reference/functions/format.md +2 -2
- package/docs/reference/functions/qr.md +2 -1
- package/docs/reference/functions/rationalize.md +13 -10
- package/docs/reference/functions/stirlingS2.md +1 -1
- package/docs/reference/functions/typeof.md +13 -13
- package/examples/advanced/add_new_datatypes/MyType.js +0 -10
- package/examples/advanced/add_new_datatypes/index.js +2 -6
- package/examples/browser/rocket_trajectory_optimization.html +2 -2
- package/lib/constants.js +3 -1
- package/lib/core/function/import.js +15 -2
- package/lib/core/typed.js +1 -1
- package/lib/expression/node/FunctionNode.js +5 -4
- package/lib/expression/parse.js +429 -466
- package/lib/function/algebra/decomposition/qr.js +1 -1
- package/lib/function/algebra/rationalize.js +41 -45
- package/lib/function/algebra/simplify/resolve.js +1 -1
- package/lib/function/algebra/simplify/simplifyCore.js +3 -3
- package/lib/function/algebra/simplify/util.js +1 -1
- package/lib/function/algebra/simplify.js +5 -0
- package/lib/function/combinatorics/stirlingS2.js +1 -1
- package/lib/function/probability/combinations.js +11 -10
- package/lib/function/probability/gamma.js +5 -13
- package/lib/function/probability/permutations.js +2 -12
- package/lib/function/probability/product.js +19 -0
- package/lib/function/string/format.js +2 -2
- package/lib/function/utils/typeof.js +13 -13
- package/lib/index.js +5 -1
- package/lib/type/bignumber/BigNumber.js +6 -2
- package/lib/type/matrix/utils/algorithm13.js +0 -2
- package/lib/type/unit/Unit.js +2 -2
- package/lib/utils/array.js +27 -19
- package/lib/utils/bignumber/formatter.js +3 -2
- package/lib/utils/number.js +15 -10
- package/lib/version.js +1 -1
- package/package.json +13 -8
- package/src/constants.js +3 -1
- package/src/core/function/import.js +15 -2
- package/src/core/typed.js +1 -1
- package/src/expression/node/FunctionNode.js +3 -4
- package/src/expression/parse.js +432 -470
- package/src/function/algebra/decomposition/qr.js +1 -1
- package/src/function/algebra/rationalize.js +41 -43
- package/src/function/algebra/simplify/resolve.js +1 -1
- package/src/function/algebra/simplify/simplifyCore.js +3 -3
- package/src/function/algebra/simplify/util.js +1 -1
- package/src/function/algebra/simplify.js +5 -0
- package/src/function/combinatorics/stirlingS2.js +1 -1
- package/src/function/probability/combinations.js +10 -8
- package/src/function/probability/gamma.js +5 -13
- package/src/function/probability/permutations.js +2 -11
- package/src/function/probability/product.js +17 -0
- package/src/function/string/format.js +2 -2
- package/src/function/utils/typeof.js +13 -13
- package/src/index.js +5 -1
- package/src/type/bignumber/BigNumber.js +2 -1
- package/src/type/matrix/utils/algorithm13.js +0 -2
- package/src/type/unit/Unit.js +2 -2
- package/src/utils/array.js +31 -23
- package/src/utils/bignumber/formatter.js +3 -2
- package/src/utils/number.js +15 -10
- package/src/version.js +1 -1
@@ -13,7 +13,7 @@ The following configuration options are available:
|
|
13
13
|
|
14
14
|
- `epsilon`. The minimum relative difference used to test equality between two
|
15
15
|
compared values. This value is used by all relational functions.
|
16
|
-
Default value is `1e-
|
16
|
+
Default value is `1e-12`.
|
17
17
|
|
18
18
|
- `matrix`. The default type of matrix output for functions.
|
19
19
|
Available values are: `'Matrix'` (default) or `'Array'`.
|
@@ -82,7 +82,7 @@ option `epsilon`. In pseudo code (without exceptions for 0, Infinity and NaN):
|
|
82
82
|
where:
|
83
83
|
|
84
84
|
- `EPSILON` is the relative difference between x and y. Epsilon is configurable
|
85
|
-
and is `1e-
|
85
|
+
and is `1e-12` by default. See [Configuration](../core/configuration.md).
|
86
86
|
- `DBL_EPSILON` is the minimum positive floating point number such that
|
87
87
|
`1.0 + DBL_EPSILON !== 1.0`. This is a constant with a value of approximately
|
88
88
|
`2.2204460492503130808472633361816e-16`.
|
package/docs/datatypes/units.md
CHANGED
@@ -183,7 +183,7 @@ when they have the same base and same value when normalized to SI units.
|
|
183
183
|
|
184
184
|
### unit.format([options])
|
185
185
|
Get a string representation of the unit. The function
|
186
|
-
will determine the best fitting prefix for the unit. See the [Format](../functions/format.md)
|
186
|
+
will determine the best fitting prefix for the unit. See the [Format](../reference/functions/format.md)
|
187
187
|
page for available options.
|
188
188
|
|
189
189
|
### unit.fromJSON(json)
|
@@ -17,7 +17,7 @@ console.log(math.simplify('x^2 + x + 3 + x^2').toString()) // '2 * x ^ 2 +
|
|
17
17
|
console.log(math.simplify('x * y * -x / (x ^ 2)').toString()) // '-y'
|
18
18
|
```
|
19
19
|
|
20
|
-
The function accepts either a string or an expression tree (`Node`) as input, and outputs a simplified expression tree (`Node`). This node tree can be transformed and evaluated as described in detail on the page [Expression trees](
|
20
|
+
The function accepts either a string or an expression tree (`Node`) as input, and outputs a simplified expression tree (`Node`). This node tree can be transformed and evaluated as described in detail on the page [Expression trees](expression_trees.md).
|
21
21
|
|
22
22
|
```js
|
23
23
|
// work with an expression tree, evaluate results
|
@@ -57,3 +57,27 @@ console.log(dh.eval({x: 3})) // '7'
|
|
57
57
|
The rules used by `math.derivative` can be found on Wikipedia:
|
58
58
|
|
59
59
|
- [Differentiation rules (Wikipedia)](http://en.wikipedia.org/wiki/Differentiation_rules)
|
60
|
+
|
61
|
+
|
62
|
+
## Rationalize
|
63
|
+
|
64
|
+
The function [`math.transform`](../reference/functions/transform.md) transforms a rationalizable expression in a rational fraction.
|
65
|
+
If rational fraction is one variable polynomial then converts the numerator and denominator in canonical form, with decreasing exponents, returning the coefficients of numerator.
|
66
|
+
|
67
|
+
```js
|
68
|
+
|
69
|
+
math.rationalize('2x/y - y/(x+1)')
|
70
|
+
// (2*x^2-y^2+2*x)/(x*y+y)
|
71
|
+
math.rationalize('(2x+1)^6')
|
72
|
+
// 64*x^6+192*x^5+240*x^4+160*x^3+60*x^2+12*x+1
|
73
|
+
math.rationalize('2x/( (2x-1) / (3x+2) ) - 5x/ ( (3x+4) / (2x^2-5) ) + 3')
|
74
|
+
// -20*x^4+28*x^3+104*x^2+6*x-12)/(6*x^2+5*x-4)
|
75
|
+
|
76
|
+
math.rationalize('x+x+x+y',{y:1}) // 3*x+1
|
77
|
+
math.rationalize('x+x+x+y',{}) // 3*x+y
|
78
|
+
|
79
|
+
const ret = math.rationalize('x+x+x+y',{},true)
|
80
|
+
// ret.expression=3*x+y, ret.variables = ["x","y"]
|
81
|
+
const ret = math.rationalize('-2+5x^2',{},true)
|
82
|
+
// ret.expression=5*x^2-2, ret.variables = ["x"], ret.coefficients=[-2,0,5]
|
83
|
+
```
|
package/docs/getting_started.md
CHANGED
@@ -19,7 +19,7 @@ Other ways to install math.js are described on the [website](http://mathjs.org/d
|
|
19
19
|
Math.js can be used in node.js and in the browser. The library must be loaded
|
20
20
|
and instantiated. When creating an instance, one can optionally provide
|
21
21
|
configuration options as described in
|
22
|
-
[Configuration](configuration.md).
|
22
|
+
[Configuration](core/configuration.md).
|
23
23
|
|
24
24
|
### ES6 modules
|
25
25
|
|
@@ -91,7 +91,7 @@ require(['mathjs'], function (math) {
|
|
91
91
|
|
92
92
|
Math.js can be used similar to JavaScript's built-in Math library. Besides that,
|
93
93
|
math.js can evaluate expressions (see [Expressions](expressions/index.md)) and
|
94
|
-
supports chaining (see [Chaining](chaining.md)).
|
94
|
+
supports chaining (see [Chaining](core/chaining.md)).
|
95
95
|
|
96
96
|
The example code below shows how to use math.js. More examples can be found in the
|
97
97
|
section [Examples](http://mathjs.org/examples/index.html).
|
@@ -38,8 +38,8 @@ math.format(value, callback)
|
|
38
38
|
For example '123.4' and '1.4e7'.
|
39
39
|
- `precision: number`
|
40
40
|
A number between 0 and 16 to round the digits of the number. In case
|
41
|
-
of notations 'exponential' and 'auto', `precision`
|
42
|
-
number of significant digits returned.
|
41
|
+
of notations 'exponential', 'engineering', and 'auto', `precision`
|
42
|
+
defines the total number of significant digits returned.
|
43
43
|
In case of notation 'fixed', `precision` defines the number of
|
44
44
|
significant digits after the decimal point.
|
45
45
|
`precision` is undefined by default.
|
@@ -35,22 +35,25 @@ Object | Expression Node | The rational polynomial of `expr` or na object {
|
|
35
35
|
## Examples
|
36
36
|
|
37
37
|
```js
|
38
|
-
math.rationalize('sin(x)+y')
|
39
|
-
|
38
|
+
math.rationalize('sin(x)+y')
|
39
|
+
// Error: There is an unsolved function call
|
40
|
+
math.rationalize('2x/y - y/(x+1)')
|
41
|
+
// (2*x^2-y^2+2*x)/(x*y+y)
|
40
42
|
math.rationalize('(2x+1)^6')
|
41
|
-
//
|
43
|
+
// 64*x^6+192*x^5+240*x^4+160*x^3+60*x^2+12*x+1
|
42
44
|
math.rationalize('2x/( (2x-1) / (3x+2) ) - 5x/ ( (3x+4) / (2x^2-5) ) + 3')
|
43
|
-
//
|
45
|
+
// -20*x^4+28*x^3+104*x^2+6*x-12)/(6*x^2+5*x-4)
|
44
46
|
math.rationalize('x/(1-x)/(x-2)/(x-3)/(x-4) + 2x/ ( (1-2x)/(2-3x) )/ ((3-4x)/(4-5x) )') =
|
45
|
-
//
|
46
|
-
//
|
47
|
+
// (-30*x^7+344*x^6-1506*x^5+3200*x^4-3472*x^3+1846*x^2-381*x)/
|
48
|
+
// (-8*x^6+90*x^5-383*x^4+780*x^3-797*x^2+390*x-72)
|
47
49
|
|
48
50
|
math.rationalize('x+x+x+y',{y:1}) // 3*x+1
|
49
51
|
math.rationalize('x+x+x+y',{}) // 3*x+y
|
50
|
-
|
51
|
-
|
52
|
-
ret =
|
53
|
-
|
52
|
+
|
53
|
+
const ret = math.rationalize('x+x+x+y',{},true)
|
54
|
+
// ret.expression=3*x+y, ret.variables = ["x","y"]
|
55
|
+
const ret = math.rationalize('-2+5x^2',{},true)
|
56
|
+
// ret.expression=5*x^2-2, ret.variables = ["x"], ret.coefficients=[-2,0,5]
|
54
57
|
```
|
55
58
|
|
56
59
|
|
@@ -29,19 +29,19 @@ math.type.Matrix | `'Matrix'` | `math.typeof(math.matrix([[1,2], [3, 4]
|
|
29
29
|
math.type.Range | `'Range'` | `math.typeof(math.range(0, 10))`
|
30
30
|
math.type.ResultSet | `'ResultSet'` | `math.typeof(math.eval('a=2\nb=3'))`
|
31
31
|
math.type.Unit | `'Unit'` | `math.typeof(math.unit('45 deg'))`
|
32
|
-
math.expression.node
|
33
|
-
math.expression.node
|
34
|
-
math.expression.node
|
35
|
-
math.expression.node
|
36
|
-
math.expression.node
|
37
|
-
math.expression.node
|
38
|
-
math.expression.node
|
39
|
-
math.expression.node
|
40
|
-
math.expression.node
|
41
|
-
math.expression.node
|
42
|
-
math.expression.node
|
43
|
-
math.expression.node
|
44
|
-
math.expression.node
|
32
|
+
math.expression.node​.AccessorNode | `'AccessorNode'` | `math.typeof(math.parse('A[2]'))`
|
33
|
+
math.expression.node​.ArrayNode | `'ArrayNode'` | `math.typeof(math.parse('[1,2,3]'))`
|
34
|
+
math.expression.node​.AssignmentNode | `'AssignmentNode'` | `math.typeof(math.parse('x=2'))`
|
35
|
+
math.expression.node​.BlockNode | `'BlockNode'` | `math.typeof(math.parse('a=2; b=3'))`
|
36
|
+
math.expression.node​.ConditionalNode | `'ConditionalNode'` | `math.typeof(math.parse('x<0 ? -x : x'))`
|
37
|
+
math.expression.node​.ConstantNode | `'ConstantNode'` | `math.typeof(math.parse('2.3'))`
|
38
|
+
math.expression.node​.FunctionAssignmentNode | `'FunctionAssignmentNode'` | `math.typeof(math.parse('f(x)=x^2'))`
|
39
|
+
math.expression.node​.FunctionNode | `'FunctionNode'` | `math.typeof(math.parse('sqrt(4)'))`
|
40
|
+
math.expression.node​.IndexNode | `'IndexNode'` | `math.typeof(math.parse('A[2]').index)`
|
41
|
+
math.expression.node​.ObjectNode | `'ObjectNode'` | `math.typeof(math.parse('{a:2}'))`
|
42
|
+
math.expression.node​.ParenthesisNode | `'ParenthesisNode'` | `math.typeof(math.parse('(2+3)'))`
|
43
|
+
math.expression.node​.RangeNode | `'RangeNode'` | `math.typeof(math.parse('1:10'))`
|
44
|
+
math.expression.node​.SymbolNode | `'SymbolNode'` | `math.typeof(math.parse('x'))`
|
45
45
|
|
46
46
|
|
47
47
|
## Syntax
|
@@ -20,16 +20,6 @@ function factory (type, config, load, typed) {
|
|
20
20
|
}
|
21
21
|
})
|
22
22
|
|
23
|
-
// define conversions if applicable
|
24
|
-
typed.addConversion({
|
25
|
-
from: 'number',
|
26
|
-
to: 'MyType',
|
27
|
-
convert: function (x) {
|
28
|
-
// convert a number to MyType
|
29
|
-
return new MyType(x)
|
30
|
-
}
|
31
|
-
})
|
32
|
-
|
33
23
|
// return the construction function, this will
|
34
24
|
// be added to math.type.MyType when imported
|
35
25
|
return MyType
|
@@ -8,9 +8,5 @@ math.import(require('./myAdd'))
|
|
8
8
|
const MyType = math.type.MyType
|
9
9
|
|
10
10
|
// use the new type
|
11
|
-
const
|
12
|
-
console.log(
|
13
|
-
|
14
|
-
// numbers will be converted to MyType
|
15
|
-
const ans2 = math.add(new MyType(4), 7) // returns MyType(11)
|
16
|
-
console.log(ans2.toString()) // outputs 'MyType:11'
|
11
|
+
const ans = math.add(new MyType(2), new MyType(3)) // returns MyType(5)
|
12
|
+
console.log(ans.toString()) // outputs 'MyType:5'
|
@@ -68,9 +68,9 @@
|
|
68
68
|
|
69
69
|
// Define the equations of motion. It is important to maintain the same argument order for each of these functions.
|
70
70
|
sim.eval("drdt(r, v, m, phi, gamma) = v sin(gamma)")
|
71
|
-
sim.eval("dvdt(r, v, m, phi, gamma) = -mu / r^2 sin(gamma) + T / m")
|
71
|
+
sim.eval("dvdt(r, v, m, phi, gamma) = -mu / r^2 * sin(gamma) + T / m")
|
72
72
|
sim.eval("dmdt(r, v, m, phi, gamma) = -T/g0/isp")
|
73
|
-
sim.eval("dphidt(r, v, m, phi, gamma) = v/r cos(gamma) * rad")
|
73
|
+
sim.eval("dphidt(r, v, m, phi, gamma) = v/r * cos(gamma) * rad")
|
74
74
|
sim.eval("dgammadt(r, v, m, phi, gamma) = (1/r * (v - mu / (r v)) * cos(gamma)) * rad")
|
75
75
|
|
76
76
|
// Again, remember to maintain the same variable order in the call to ndsolve.
|
package/lib/constants.js
CHANGED
@@ -80,7 +80,9 @@ function factory(type, config, load, typed, math) {
|
|
80
80
|
}
|
81
81
|
|
82
82
|
// complex i
|
83
|
-
|
83
|
+
if (type.Complex) {
|
84
|
+
setConstant(math, 'i', type.Complex.I);
|
85
|
+
}
|
84
86
|
|
85
87
|
// meta information
|
86
88
|
setConstant(math, 'version', require('./version'));
|
@@ -153,6 +153,15 @@ function factory(type, config, load, typed, math) {
|
|
153
153
|
}
|
154
154
|
}
|
155
155
|
|
156
|
+
function _deleteTransform(name) {
|
157
|
+
delete math.expression.transform[name];
|
158
|
+
if (allowedInExpressions(name)) {
|
159
|
+
math.expression.mathWithTransform[name] = math[name];
|
160
|
+
} else {
|
161
|
+
delete math.expression.mathWithTransform[name];
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
156
165
|
/**
|
157
166
|
* Create a wrapper a round an function which converts the arguments
|
158
167
|
* to their primitive values (like convert a Matrix to Array)
|
@@ -219,7 +228,9 @@ function factory(type, config, load, typed, math) {
|
|
219
228
|
if (factory.lazy !== false) {
|
220
229
|
lazy(namespace, name, resolver);
|
221
230
|
|
222
|
-
if (
|
231
|
+
if (existingTransform) {
|
232
|
+
_deleteTransform(name);
|
233
|
+
} else {
|
223
234
|
if (factory.path === 'expression.transform' || factoryAllowedInExpressions(factory)) {
|
224
235
|
lazy(math.expression.mathWithTransform, name, resolver);
|
225
236
|
}
|
@@ -227,7 +238,9 @@ function factory(type, config, load, typed, math) {
|
|
227
238
|
} else {
|
228
239
|
namespace[name] = resolver();
|
229
240
|
|
230
|
-
if (
|
241
|
+
if (existingTransform) {
|
242
|
+
_deleteTransform(name);
|
243
|
+
} else {
|
231
244
|
if (factory.path === 'expression.transform' || factoryAllowedInExpressions(factory)) {
|
232
245
|
math.expression.mathWithTransform[name] = resolver();
|
233
246
|
}
|
package/lib/core/typed.js
CHANGED
@@ -150,7 +150,7 @@ exports.create = function create(type) {
|
|
150
150
|
// define all types. The order of the types determines in which order function
|
151
151
|
// arguments are type-checked (so for performance it's important to put the
|
152
152
|
// most used types first).
|
153
|
-
typed.types = [{ name: 'number', test: type.isNumber }, { name: 'Complex', test: type.isComplex }, { name: 'BigNumber', test: type.isBigNumber }, { name: 'Fraction', test: type.isFraction }, { name: 'Unit', test: type.isUnit }, { name: 'string', test: type.isString }, { name: 'Array', test: type.isArray }, { name: 'Matrix', test: type.isMatrix }, { name: 'DenseMatrix', test: type.isDenseMatrix }, { name: 'SparseMatrix', test: type.isSparseMatrix }, { name: 'Range', test: type.isRange }, { name: 'Index', test: type.isIndex }, { name: 'boolean', test: type.isBoolean }, { name: 'ResultSet', test: type.isResultSet }, { name: 'Help', test: type.isHelp }, { name: 'function', test: type.isFunction }, { name: 'Date', test: type.isDate }, { name: 'RegExp', test: type.isRegExp }, { name: 'null', test: type.isNull }, { name: 'undefined', test: type.isUndefined }, { name: 'OperatorNode', test: type.isOperatorNode }, { name: 'ConstantNode', test: type.isConstantNode }, { name: 'SymbolNode', test: type.isSymbolNode }, { name: 'ParenthesisNode', test: type.isParenthesisNode }, { name: 'FunctionNode', test: type.isFunctionNode }, { name: 'FunctionAssignmentNode', test: type.isFunctionAssignmentNode }, { name: 'ArrayNode', test: type.isArrayNode }, { name: 'AssignmentNode', test: type.isAssignmentNode }, { name: 'BlockNode', test: type.isBlockNode }, { name: 'ConditionalNode', test: type.isConditionalNode }, { name: 'IndexNode', test: type.isIndexNode }, { name: 'RangeNode', test: type.isRangeNode }, { name: 'Node', test: type.isNode }, { name: 'Object', test: type.isObject // order 'Object' last, it
|
153
|
+
typed.types = [{ name: 'number', test: type.isNumber }, { name: 'Complex', test: type.isComplex }, { name: 'BigNumber', test: type.isBigNumber }, { name: 'Fraction', test: type.isFraction }, { name: 'Unit', test: type.isUnit }, { name: 'string', test: type.isString }, { name: 'Array', test: type.isArray }, { name: 'Matrix', test: type.isMatrix }, { name: 'DenseMatrix', test: type.isDenseMatrix }, { name: 'SparseMatrix', test: type.isSparseMatrix }, { name: 'Range', test: type.isRange }, { name: 'Index', test: type.isIndex }, { name: 'boolean', test: type.isBoolean }, { name: 'ResultSet', test: type.isResultSet }, { name: 'Help', test: type.isHelp }, { name: 'function', test: type.isFunction }, { name: 'Date', test: type.isDate }, { name: 'RegExp', test: type.isRegExp }, { name: 'null', test: type.isNull }, { name: 'undefined', test: type.isUndefined }, { name: 'OperatorNode', test: type.isOperatorNode }, { name: 'ConstantNode', test: type.isConstantNode }, { name: 'SymbolNode', test: type.isSymbolNode }, { name: 'ParenthesisNode', test: type.isParenthesisNode }, { name: 'FunctionNode', test: type.isFunctionNode }, { name: 'FunctionAssignmentNode', test: type.isFunctionAssignmentNode }, { name: 'ArrayNode', test: type.isArrayNode }, { name: 'AssignmentNode', test: type.isAssignmentNode }, { name: 'BlockNode', test: type.isBlockNode }, { name: 'ConditionalNode', test: type.isConditionalNode }, { name: 'IndexNode', test: type.isIndexNode }, { name: 'RangeNode', test: type.isRangeNode }, { name: 'Node', test: type.isNode }, { name: 'Object', test: type.isObject // order 'Object' last, it matches on other classes too
|
154
154
|
}];
|
155
155
|
|
156
156
|
// TODO: add conversion from BigNumber to number?
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
4
4
|
|
5
|
+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
6
|
+
|
5
7
|
var latex = require('../../utils/latex');
|
6
8
|
var escape = require('../../utils/string').escape;
|
7
9
|
var hasOwnProperty = require('../../utils/object').hasOwnProperty;
|
@@ -84,7 +86,6 @@ function factory(type, config, load, typed, math) {
|
|
84
86
|
var evalArgs = map(this.args, function (arg) {
|
85
87
|
return arg._compile(math, argNames);
|
86
88
|
});
|
87
|
-
// const jsScope = compileScope(defs, args) // TODO: jsScope
|
88
89
|
|
89
90
|
if (type.isSymbolNode(this.fn)) {
|
90
91
|
// we can statically determine whether the function has an rawArgs property
|
@@ -97,7 +98,7 @@ function factory(type, config, load, typed, math) {
|
|
97
98
|
// "raw" evaluation
|
98
99
|
var rawArgs = this.args;
|
99
100
|
return function evalFunctionNode(scope, args, context) {
|
100
|
-
return (name in scope ? getSafeProperty(scope, name) : fn)(rawArgs, math, scope);
|
101
|
+
return (name in scope ? getSafeProperty(scope, name) : fn)(rawArgs, math, _extends({}, scope, args));
|
101
102
|
};
|
102
103
|
} else {
|
103
104
|
// "regular" evaluation
|
@@ -132,7 +133,7 @@ function factory(type, config, load, typed, math) {
|
|
132
133
|
validateSafeMethod(object, prop);
|
133
134
|
var isRaw = object[prop] && object[prop].rawArgs;
|
134
135
|
|
135
|
-
return isRaw ? object[prop](_rawArgs, math, scope) // "raw" evaluation
|
136
|
+
return isRaw ? object[prop](_rawArgs, math, _extends({}, scope, args)) // "raw" evaluation
|
136
137
|
: object[prop].apply(object, map(evalArgs, function (evalArg) {
|
137
138
|
// "regular" evaluation
|
138
139
|
return evalArg(scope, args, context);
|
@@ -148,7 +149,7 @@ function factory(type, config, load, typed, math) {
|
|
148
149
|
var fn = evalFn(scope, args, context);
|
149
150
|
var isRaw = fn && fn.rawArgs;
|
150
151
|
|
151
|
-
return isRaw ? fn(_rawArgs2, math, scope) // "raw" evaluation
|
152
|
+
return isRaw ? fn(_rawArgs2, math, _extends({}, scope, args)) // "raw" evaluation
|
152
153
|
: fn.apply(fn, map(evalArgs, function (evalArg) {
|
153
154
|
// "regular" evaluation
|
154
155
|
return evalArg(scope, args, context);
|