public class Constant extends Object implements Evaluator
PI
and E
are certain Constant
objects
representing the appropriate mathematical constant.
Constant
will be created by the method Type.getEvaluator(Symbol,Context)
to return the Evaluator - that
created Constant
- for a Symbol
representing
a constant number. Such Constants
are instances of
RealConstant
or ComplexConstant
in any case because they
are part of an evaluator-tree.Symbol
represents no constant
number but nevertheless a Constant
like "pi" or "e", the
method getConstant(Symbol,Type)
is used to return that
Constant
object.Modifier and Type | Field and Description |
---|---|
static Constant[] |
CONSTANTS
An array of all
static final Constant fields of this class. |
static Constant |
E
Represents the mathematical constant e=2.7182....
|
static Constant |
I
Represents the complex constant i=sqrt(-1).
|
static Constant |
PI
Represents the mathematical constant pi=3.1415....
|
Constructor and Description |
---|
Constant(String n,
Object val,
Type t)
Creates a new
Constant with the name n ,
the value val and the Type t . |
Modifier and Type | Method and Description |
---|---|
Object |
evaluate()
Evaluates this
Constant by returning its value. |
static Constant |
getConstant(Symbol s,
Type t)
Either returns the
Constant represented by the specified
Symbol and Type if contained by the
CONSTANTS array, or returns null if an appropriate
Constant does not exist in that array. |
Type |
getReturnType()
Returns the
Type of this Constant's value. |
static boolean |
isConstant(Symbol s)
Returns
true if the specified Symbol represents
a Constant contained by the CONSTANTS array,
false otherwise. |
String |
toString()
Returns the name of this
Constant . |
public static final Constant[] CONSTANTS
static final Constant
fields of this class.public static final Constant E
Type
is RealType.TYPE
.Math.E
public static final Constant I
Type
is ComplexType.TYPE
.Complex
public static final Constant PI
Type
is RealType.TYPE
.Math.PI
public Constant(String n, Object val, Type t)
Constant
with the name n
,
the value val
and the Type t
. The
Type
is necessary for the correct evaluation of this
Constant
in relation to other Evaluators
with different evaluation Types
..n
- the name for the new Constant
.val
- the value for the new Constant
.t
- the Type
of the value of the new
Constant
.public Object evaluate()
Constant
by returning its value.evaluate
in interface Evaluator
Constant
as an Object
.AbstractRealEvaluator.getRealValue(Real)
,
AbstractComplexEvaluator.getComplexValue(Complex)
,
AbstractRealVectorEvaluator.getRealVectorValue(RealVector)
,
AbstractComplexVectorEvaluator.getComplexVectorValue(ComplexVector)
public static Constant getConstant(Symbol s, Type t)
Constant
represented by the specified
Symbol
and Type
if contained by the
CONSTANTS
array, or returns null
if an appropriate
Constant
does not exist in that array.
For example, this method will be used for the evaluation of
Symbols
to decide if that Symbol
is representing
a Variable
or a Constant
.s
- the Symbol
representing the Constant
to be searched for in the CONSTANTS
array.t
- the Type
the Constant
must be of.Constant
represented by the specified
Symbol
and Type
if contained by the
CONSTANTS
array, otherwise null
.Type.getEvaluator(Symbol,Context)
public Type getReturnType()
Type
of this Constant's
value.getReturnType
in interface Evaluator
Type
of this Constant's
value.public static boolean isConstant(Symbol s)
true
if the specified Symbol
represents
a Constant
contained by the CONSTANTS
array,
false
otherwise.