Esempio n. 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));
        }
Esempio n. 2
0
        public static Value Get(Complex value)
        {
            if (value.Im == 0.0)
            {
                return(RealValue.Get(value.Re));
            }
            ComplexValue ret;

            cachedValues.TryGetValue(value, out ret);
            if (ret == null)
            {
                ret = new ComplexValue(value);
            }
            return(ret);
        }
Esempio n. 3
0
        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);
        }