package calc;

/** Negation (unary minus) formulas for the calculator.
 * @author Gary T. Leavens
 */
public class Negate extends UnaryFormula {
   
    /** Initialize this negation object.
     * @param reg, the register to negate when run.
     */
    //@ requires 0 <= reg && reg < Registers.NUM_REGS;
    //@ assignable this.left;
    //@ ensures this.left == reg;
    public Negate(int reg) {
        super(reg);
    }

    /** Negate the value in the register.
     */
    //@ also
    //@   assignable \nothing;
    //@   ensures \result == Registers.get(left);
    public /*@ pure @*/ double evaluate() {
        return - leftValue();
    }
    
    public String toString() {
        return "-" + super.toString();
    }
}
