mathExpr.evaluator.Type
is an interface necessary
to combine different types of numbers together in one expression. For any
of these numerous combinations (real+real, real+complex, complex+real,
complex+complex, ...) there is one appropriate Evaluator
class.
mathExpr.evaluator.Evaluator
is the interface for
all of these evaluators and defines the method getReturnType()
returning the Type
of the
evaluated result. (UML-Diagramm)
Example:
default type: RealType.TYPE
expression: "1+2" (UML-Diagramm expression-tree)
evaluator-tree: RealPlusRealEvaluator
(UML-Diagramm)
result type: real
The default type is the Type
, all
Symbols
representing constant values (like: "2", "3",
"1000") will be evaluated to. The default type is the choise by yourself only.
If you know, that there will be no complex number in your expression or you
even want that there must not be any complex, you choose
RealType.TYPE
as your default type. Otherwise you choose
ComplexType.TYPE
as your default type.
Note: If you choose ComplexType.TYPE
as your default type
all symbols representing a constant value will be converted to complex values
even if they are real (and they are all real). That is because the
definition of the predefined square root function relies on the argument
type. Example:
default type: ComplexType.TYPE
expression: "sqrt(-1)" (UML-Diagramm expression-tree)
evaluation-tree: The evaluator for "1" is a Constant
object of Type
complex.
That's why the UnaryOperation
"-(1)" will result a complex to.
If "-1" was evaluated to a real number, square root of "-1" would not be
defined. "-1" has to be converted to "-1*0i" for correct evaluation in a
complex context. This conversion proceeds at the mapping from the
Symbol
(Expression
)
to the Constant
(Evaluator
)
object (see documentation of ComplexType.getEvaluator(Symbol,Context))
.
Whenever you need an instance of
Type
, you do not need to create it with the constructor
(it's not possible). Instead of that, every Type
implementation
has a final static
field TYPE
which has
to be used.