| java.lang.Object edu.hws.jcm.data.Constant
All known Subclasses: edu.hws.jcm.data.Variable,
Constant | public class Constant implements Expression,ExpressionCommand,MathObject(Code) | | A Constant is a Value that represents a constant real number. (The value doesn't have to
be constant in sub-classes, since the member that stores the value is protected, not private.)
A Constant doesn't necessarily need a name. If the name is null, then the print string for the
Constant is the value of the constant. If it has a non-null name, then the print string
is the name. (Note that, as for any MathObject, if the name is null, than the Constant can't
be added to a Parser.) Constant objects are used to represent the mathematical constants
pi and e.
A Constant is both an Expression and an ExpressionCommand. Since it is an ExpressionCommand,
it can occur as a command in an ExpressionProgram. In that case, it simply represens a named constant
occurs in an expression.
|
Field Summary | |
protected double | value The value of this Constant. |
Constructor Summary | |
public | Constant(double value) Create an unnamed Constant with the given value and null name. | public | Constant(String name, double value) Create a Constant with the given name and value. |
value | protected double value(Code) | | The value of this Constant.
|
Constant | public Constant(double value)(Code) | | Create an unnamed Constant with the given value and null name.
|
Constant | public Constant(String name, double value)(Code) | | Create a Constant with the given name and value.
The name can be null.
|
appendOutputString | public void appendOutputString(ExpressionProgram prog, int myIndex, StringBuffer buffer)(Code) | | Append the print string for this Constant to the buffer. (The values of prog and
myIndex are irrelevant.)
|
apply | public void apply(StackOfDouble stack, Cases cases)(Code) | | Apply the Constant to the stack. This is done by pushing the value of
the constant onto the stack. The evaluation of a constant doesn't have any
"cases", so there is no need to record any information in cases.
|
compileDerivative | public void compileDerivative(ExpressionProgram prog, int myIndex, ExpressionProgram deriv, Variable wrt)(Code) | | Add a commands to deriv to evaluate the derivative of this Constant with respect to the
variable. The derivative is 0, so the only command is the constant 0 (which really
represents the stack operation "push 0"). The program and the position of the Constant
in that program are irrelevant.
|
dependsOn | public boolean dependsOn(Variable x)(Code) | | Retrun false, since the value of this Constant is independent of the value of x.
|
derivative | public Expression derivative(Variable wrt)(Code) | | Return the derivative of this Constant with respect to the variable wrt.
The derivative is another Constant with value zero.
|
extent | public int extent(ExpressionProgram prog, int myIndex)(Code) | | Return the number of locations that this Constant uses in the program.
The value is always 1, since the constant is a complete sub-expression
in itself.
|
getName | public String getName()(Code) | | Return the name of this Constant. It can be null.
|
getVal | public double getVal()(Code) | | Return the value of this Constant.
|
getValueWithCases | public double getValueWithCases(Cases cases)(Code) | | Return the value of the Constant. Since a constant is continuous function,
there is only one "case", so no case information needs to be recorded in cases.
|
setName | public void setName(String name)(Code) | | Set the name of this Constant. (Note that this should not be done
if the Constant has been registered with a Parser.)
|
toString | public String toString()(Code) | | Return the print string representing this Constant. The string is the
name of the constant, if that is non-null. Otherwise, it is the value
of the constant.
|
|
|