|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.webcompmath.data.Constant
public class Constant
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 | |
---|---|
Constant()
default constructor, intended only for use in GUI building |
|
Constant(double value)
Create an unnamed Constant with the given value and null name. |
|
Constant(java.lang.String name,
double value)
Create a Constant with the given name and value. |
Method Summary | |
---|---|
void |
appendOutputString(ExpressionProgram prog,
int myIndex,
java.lang.StringBuffer buffer)
Append the print string for this Constant to the buffer. |
void |
apply(StackOfDouble stack,
Cases cases)
Apply the Constant to the stack. |
void |
compileDerivative(ExpressionProgram prog,
int myIndex,
ExpressionProgram deriv,
Variable wrt)
Add a commands to deriv to evaluate the derivative of this Constant with respect to the variable. |
boolean |
dependsOn(Variable x)
Return false, since the value of this Constant is independent of the value of x. |
Expression |
derivative(Variable wrt)
Return the derivative of this Constant with respect to the variable wrt. |
int |
extent(ExpressionProgram prog,
int myIndex)
Return the number of locations that this Constant uses in the program. |
java.lang.String |
getName()
Return the name of this Constant. |
double |
getVal()
Return the value of this Constant. |
double |
getValueWithCases(Cases cases)
Return the value of the Constant. |
void |
setName(java.lang.String name)
Set the name of this Constant. |
java.lang.String |
toString()
Return the print string representing this Constant. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected double value
Constructor Detail |
---|
public Constant()
public Constant(double value)
value
- value to usepublic Constant(java.lang.String name, double value)
name
- name of constantvalue
- it's valueMethod Detail |
---|
public java.lang.String getName()
getName
in interface MathObject
public void setName(java.lang.String name)
setName
in interface MathObject
name
- name of the constantpublic double getVal()
getVal
in interface Value
public double getValueWithCases(Cases cases)
getValueWithCases
in interface Expression
cases
- the cases to use
public Expression derivative(Variable wrt)
derivative
in interface Expression
wrt
- variable wirh respect to
public java.lang.String toString()
toString
in interface Expression
toString
in class java.lang.Object
public void apply(StackOfDouble stack, Cases cases)
apply
in interface ExpressionCommand
stack
- the stack to usecases
- the cases to usepublic void compileDerivative(ExpressionProgram prog, int myIndex, ExpressionProgram deriv, Variable wrt)
compileDerivative
in interface ExpressionCommand
prog
- program containing the constantmyIndex
- location of the constantderiv
- the derivativewrt
- variable with respect topublic int extent(ExpressionProgram prog, int myIndex)
extent
in interface ExpressionCommand
prog
- program containing the constantmyIndex
- location of the constant
public boolean dependsOn(Variable x)
dependsOn
in interface Expression
dependsOn
in interface ExpressionCommand
x
- variable to check if depends on
public void appendOutputString(ExpressionProgram prog, int myIndex, java.lang.StringBuffer buffer)
appendOutputString
in interface ExpressionCommand
prog
- program containing the constantmyIndex
- location of the constantbuffer
- string to append
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |