FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mathjs/src/expression/function/evaluate.js at develop · Josef37/mathjs · GitHub
Josef37
/
mathjs
Public
forked from
josdejong/mathjs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
mathjs
/
src
/
expression
/
function
/
evaluate.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (58 loc) · 1.89 KB
Breadcrumbs
mathjs
/
src
/
expression
/
function
/
evaluate.js
Copy path
File metadata and controls
63 lines (58 loc) · 1.89 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import
{
deepMap
}
from
'../../utils/collection.js'
import
{
factory
}
from
'../../utils/factory.js'
const
name
=
'evaluate'
const
dependencies
=
[
'typed'
,
'parse'
]
export
const
createEvaluate
=
/* #__PURE__ */
factory
(
name
,
dependencies
,
(
{
typed
,
parse
}
)
=>
{
/**
* Evaluate an expression.
*
* Note the evaluating arbitrary expressions may involve security risks,
* see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information.
*
* Syntax:
*
* math.evaluate(expr)
* math.evaluate(expr, scope)
* math.evaluate([expr1, expr2, expr3, ...])
* math.evaluate([expr1, expr2, expr3, ...], scope)
*
* Example:
*
* math.evaluate('(2+3)/4') // 1.25
* math.evaluate('sqrt(3^2 + 4^2)') // 5
* math.evaluate('sqrt(-4)') // 2i
* math.evaluate(['a=3', 'b=4', 'a*b']) // [3, 4, 12]
*
* let scope = {a:3, b:4}
* math.evaluate('a * b', scope) // 12
*
* See also:
*
* parse, compile
*
*
@param
{
string | string[] | Matrix
} expr The expression to be evaluated
*
@param
{
Object
} [scope] Scope to read/write variables
*
@return
{
*
} The result of the expression
*
@throws
{
Error
}
*/
return
typed
(
name
,
{
string
:
function
(
expr
)
{
const
scope
=
{
}
return
parse
(
expr
)
.
compile
(
)
.
evaluate
(
scope
)
}
,
'string, Object'
:
function
(
expr
,
scope
)
{
return
parse
(
expr
)
.
compile
(
)
.
evaluate
(
scope
)
}
,
'Array | Matrix'
:
function
(
expr
)
{
const
scope
=
{
}
return
deepMap
(
expr
,
function
(
entry
)
{
return
parse
(
entry
)
.
compile
(
)
.
evaluate
(
scope
)
}
)
}
,
'Array | Matrix, Object'
:
function
(
expr
,
scope
)
{
return
deepMap
(
expr
,
function
(
entry
)
{
return
parse
(
entry
)
.
compile
(
)
.
evaluate
(
scope
)
}
)
}
}
)
}
)
Back
|
FazBrowse Home
|
New Git URL