Exemplo n.º 1
0
        public static RealValue Get(double value)
        {
            RealValue ret;

            cachedValues.TryGetValue(value, out ret);
            if (ret == null)
            {
                ret = new RealValue(value, false);
            }
            return(ret);
        }
Exemplo 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);
        }
Exemplo 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);
        }