-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the math-expressions wiki! This page will be a quick guide on the syntax required by the parser.
MathExpression.parse("1 + 1 - 3 + x").setVariable("x", 9).evaluate(); // output: 8
While floating-point notation is not supported, any real number is supported:
-
1
,10
,-1024
-
0.2454
,-3.04593
,9.3333
Please do note that numbers are still subject to floating-point inaccuracy.
Currently, these operators are supported (and executed in order of):
- Power (
^
) - Multiply, divide (
*
&/
) - Add, subtract (
+
&-
)
Opening parentheses are paired with the closest closing parentheses, where inner most parentheses are prioritized to match (basically how you would expect them to match in programming languages).
The program identifies variables as a token that contains characters that isn't a number or an operator. If the variable is followed by a (
, the program will then attempt to call the function with that name instead (e.g. variable * (1)
vs function(1)
).