private void DoDivide(Stack <Datum> stack) { NumericDatum b = stack.Pop() as NumericDatum; NumericDatum a = stack.Pop() as NumericDatum; NumericDatum result; if (a == null) { if (b == null) { result = new NumericDatum(1); } else { result = new NumericDatum(b.number); } } else if (b == null) { result = new NumericDatum(a.number); } else { result = new NumericDatum(a.number / b.number); } stack.Push(result); }
private void DoSubtract(Stack <Datum> stack) { NumericDatum b = stack.Pop() as NumericDatum; NumericDatum a = stack.Pop() as NumericDatum; NumericDatum result; if (a == null) { if (b == null) { result = new NumericDatum(0); } else { result = new NumericDatum(-b.number); } } else if (b == null) { result = new NumericDatum(a.number); } else { result = new NumericDatum(a.number - b.number); } stack.Push(result); }
private void DoMaximum(Stack <Datum> stack) { NumericDatum b = stack.Pop() as NumericDatum; NumericDatum a = stack.Pop() as NumericDatum; NumericDatum result; if (a == null) { if (b == null) { result = new NumericDatum(0); } else { result = new NumericDatum(b.number); } } else if (b == null) { result = new NumericDatum(a.number); } else { result = new NumericDatum(a.number > b.number ? a.number : b.number); } stack.Push(result); }
public override bool Equals(object obj) { NumericDatum other = obj as NumericDatum; if (other == null) { return(false); } return(number == other.number); }
private void DoModulo(Stack <Datum> stack) { NumericDatum b = stack.Pop() as NumericDatum; NumericDatum a = stack.Pop() as NumericDatum; NumericDatum result; if (a == null) { result = new NumericDatum(0); } else if (b == null) { result = new NumericDatum(a.number); } else { result = new NumericDatum(a.number % b.number); } stack.Push(result); }
private void DoLessThanOrEquals(Stack <Datum> stack) { NumericDatum b = stack.Pop() as NumericDatum; NumericDatum a = stack.Pop() as NumericDatum; BooleanDatum result; if (a == null) { result = new BooleanDatum(true); } else if (b == null) { result = new BooleanDatum(false); } else { result = new BooleanDatum(a.number <= b.number); } stack.Push(result); }