Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public override bool Equals(object obj)
        {
            NumericDatum other = obj as NumericDatum;

            if (other == null)
            {
                return(false);
            }
            return(number == other.number);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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);
        }