Exemple #1
0
        public override Value DoOperation(Operator op, Value right, bool assign)
        {
            long?newValue  = null;
            bool?boolValue = null;

            if (right == null)
            {
                newValue = Unary(op, Value);
            }
            else
            {
                var num = right as NumberValue;
                if (num == null)
                {
                    return(null);
                }
                var other = num.AsDiscrete;
                if (num.IsDiscrete)
                {
                    newValue = BinaryOperation(op, Value, other);
                    if (newValue == null)
                    {
                        boolValue = Test(op, Value, other);
                    }
                }
                else if (num.IsReal)
                {
                    double?rValue = RealValue.BinaryOperation(op, Real, num.Real);
                    if (rValue.HasValue)
                    {
                        return(RealValue.Get(rValue.Value));
                    }
                    boolValue = RealValue.Test(op, Real, num.Real);
                }
                else
                {
                    var     complex = AsComplex;
                    Complex?cValue  = ComplexValue.BinaryOperation(op, complex, num.AsComplex);
                    if (cValue.HasValue)
                    {
                        return(ComplexValue.Get(cValue.Value));
                    }
                    boolValue = ComplexValue.Test(op, complex, num.AsComplex);
                }
            }
            if (boolValue.HasValue)
            {
                return(BoolValue.Get(boolValue.Value));
            }
            if (!newValue.HasValue)
            {
                return(null);
            }
            if (assign)
            {
                return(SetValue(newValue.Value));
            }
            return(Get(newValue.Value));
        }