package rebelsky.pal; /** * A floating-point constant for PAL. * * @author Samuel A. Rebelsky * @version 1.0 of December 2002 */ public class FConstant extends Variable { // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** The value of the constant. */ float value; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Build a new floating-point constannt. */ public FConstant(float val) { this.value = val; } // IConstant() // +---------+----------------------------------------------------------- // | Methods | // +---------+ /** * Get the float stored in this constant. */ public float fget(Computer hal) { return this.value; } // fget() /** * Get the integer stored in this constant. */ public int iget(Computer hal) { return Float.floatToIntBits(this.value); } // iget(Computer) /** * Fail to set the value of the constant. * * @exception Exception * Whenever this procedure is called (you can't change constants). */ public void fset(Computer hal, float newval) throws Exception { throw new Exception("Can't change the value of constants."); } // fset(float) public void iset(Computer hal, int newval) throws Exception { throw new Exception("Can't change the value of constants."); } // iset(int) /** Convert the location to a string (usually for printing). */ public String toString() { return "$$" + this.value; } // toString() } // class FConstant