Package cs2110

Class Constant

java.lang.Object
cs2110.Constant
All Implemented Interfaces:
Expression

public class Constant extends Object implements Expression
An expression tree node representing a fixed real number.
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    Constant(double value)
    Create a node representing the value `value`.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    A Constant has no dependencies.
    boolean
    equals(Object other)
    Return whether `other` is a Constant of the same class with the same value.
    double
    eval(VarTable vars)
    Return this node's value.
    int
     
    Return the decimal representation of this node's value (with sufficient precision to reproduce its binary value).
    int
    No operations are required to evaluate a Constant's value.
    Return self (a Constant is already fully optimized).
    Return the decimal representation of this node's value (with sufficient precision to reproduce its binary value).
     

    Methods inherited from class java.lang.Object Link icon

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details Link icon

    • Constant Link icon

      public Constant(double value)
      Create a node representing the value `value`.
  • Method Details Link icon

    • eval Link icon

      public double eval(VarTable vars)
      Return this node's value.
      Specified by:
      eval in interface Expression
    • opCount Link icon

      public int opCount()
      No operations are required to evaluate a Constant's value.
      Specified by:
      opCount in interface Expression
    • infixString Link icon

      public String infixString()
      Return the decimal representation of this node's value (with sufficient precision to reproduce its binary value).
      Specified by:
      infixString in interface Expression
    • postfixString Link icon

      public String postfixString()
      Return the decimal representation of this node's value (with sufficient precision to reproduce its binary value).
      Specified by:
      postfixString in interface Expression
    • equals Link icon

      public boolean equals(Object other)
      Return whether `other` is a Constant of the same class with the same value.
      Overrides:
      equals in class Object
    • dependencies Link icon

      public Set<String> dependencies()
      A Constant has no dependencies.
      Specified by:
      dependencies in interface Expression
    • optimize Link icon

      public Expression optimize(VarTable vars)
      Return self (a Constant is already fully optimized).
      Specified by:
      optimize in interface Expression
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object
    • hashCode Link icon

      public int hashCode()
      Overrides:
      hashCode in class Object