Example #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));
        }
Example #2
0
        public override Value DoOperation(Operator op, Value right, bool assign)
        {
            double?newValue   = null;
            bool?  boolResult = null;

            if (right == null)
            {
                newValue = Unary(op, Value);
            }
            else
            {
                var num = right as NumberValue;
                if (num == null)
                {
                    return(null);
                }
                if (!num.IsReal)
                {
                    Complex?cValue = ComplexValue.BinaryOperation(op, AsComplex, num.AsComplex);
                    if (cValue.HasValue)
                    {
                        return(ComplexValue.Get(cValue.Value));
                    }
                    boolResult = ComplexValue.Test(op, AsComplex, num.AsComplex);
                }
                else
                {
                    newValue = BinaryOperation(op, Value, num.Real);
                    if (newValue == null)
                    {
                        boolResult = Test(op, Value, num.Real);
                    }
                }
            }
            if (boolResult.HasValue)
            {
                return(BoolValue.Get(boolResult.Value));
            }
            if (!newValue.HasValue)
            {
                return(null);
            }
            if (assign)
            {
                return(SetValue(newValue.Value));
            }
            return(Get(newValue.Value));
        }
Example #3
0
            public override Value DoOperation(Operator op, Value right, bool assign)
            {
                if (right is NoneValue)
                {
                    switch (op)
                    {
                    case Operator.Equal:
                    case Operator.In:
                        return(BoolValue.Get(true));

                    case Operator.NotEqual:
                    case Operator.NotIn:
                        return(BoolValue.Get(false));
                    }
                }
                return(null);
            }
        public override Value DoOperation(Operator op, Value right, bool assign)
        {
            var     number    = right as NumberValue;
            Complex?newValue  = null;
            bool?   boolValue = null;

            if (number == null)
            {
                switch (op)
                {
                case Operator.Negate:
                    newValue = -Value;
                    break;

                case Operator.Substitute:
                case Operator.Evaluate:
                    return(this);

                case Operator.Magnitude:
                    return(RealValue.Get(Magnitude));
                }
            }
            else
            {
                newValue = BinaryOperation(op, Value, number.AsComplex);
                if (newValue == null)
                {
                    boolValue = Test(op, Value, number.AsComplex);
                }
            }
            if (boolValue.HasValue)
            {
                return(BoolValue.Get(boolValue.Value));
            }
            else if (newValue.HasValue)
            {
                return(assign ? SetValue(newValue.Value) : Get(newValue.Value));
            }
            return(null);
        }