using System; using System.Collections.Generic; using System.Linq; using System.Text; using SingularSys.Jep; using SingularSys.Jep.Functions; using SingularSys.Jep.Types; namespace HalfTest { public class Half : PostfixMathCommand { // Constructor sets the number of required parameters for half public Half() { numberOfParameters = 1; } public override void Run(Stack inStack) { // check the stack CheckStack(inStack); // get the parameter from the stack Object param = inStack.Pop(); // check whether the argument is of the right type if (param is JepDouble) { // calculate the result double r = ((JepDouble)param).DoubleValue / 2; // push the result on the inStack inStack.Push(new JepDouble(r)); } else { throw new EvaluationException("Invalid parameter type"); } } } }