ExpressionParser class final
Parses mathematical expressions with real numbers and the x
variable (if
any). The only allowed variable name is x
: any other type of value isn't
recognized. Some expressions examples are:
"3*x - 6"
"5 + 3 * (4^2)"
sqrt(x - 3) - log(10)
Note that the multiplication requires the star (*) symbol. Here's a list of all the operators supported by the parser:
-
- (sum)
-
- (difference)
-
- (product)
- / (division)
- ^ (power)
- sqrt(x) (square root of
x
) - sin(x) (sine of
x
) - cos(x) (cosine of
x
) - tan(x) (tangent of
x
) - log(x) (natural logarithm of
x
) - acos(x) (arc cosine of
x
) - asin(x) (arc sine of
x
) - atan(x) (arc tangent of
x
) - csc(x) (cosecant of
x
) - sec(x) (secant of
x
)
An exception of type ExpressionParserException is thrown if the parsed is malformed. This parser is also able to recognize some constants:
- pi (pi, the ratio of the circumference on the diameter)
- e (Euler's number)
- sqrt2 (the square root of 2)
- sqrt3 (the square root of 3)
- G (Gauss constant)
Constructors
- ExpressionParser()
-
Builds a new expression parser that accepts strings with a single
x
variable. For example, valid expressions are:const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
evaluate(
String expression) → double -
Evaluates the mathematical
expression
and returns the result. This method has to be used to evaluate those expression that do not contain thex
variable. For example: -
evaluateOn(
String expression, double evaluationPoint) → double -
Evaluates the mathematical
expression
and replaces thex
variable with the value of the givenevaluationPoint
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited