예제 #1
0
        public override object Evaluate()
        {
            Complex value  = LeftExpression.EvaluateAsComplex();
            int     digits = RightExpression.EvaluateAsInt32();

            return(Complex.Round(value, digits));
        }
 public override void GetIntCode(BuildICCode codeManager)
 {
     RightExpression.GetIntCode(codeManager);
     var(x, type) = codeManager.variableManager.Peek(Id.Text);
     if (type is null)
     {
         type = codeManager.virtualTable.getAttrType(codeManager.variableManager.ClassName, Id.Text);
     }
     if ((RightExpression.StaticType.Text == "Int" ||
          RightExpression.StaticType.Text == "Bool" ||
          RightExpression.StaticType.Text == "String") &&
         type == "Object")
     {
         codeManager.codeLines.Add(new ICPushParams(codeManager.variableManager.PeekCounter()));
         codeManager.codeLines.Add(new ICCallLabel(new ICLabel("_wrapper", RightExpression.StaticType.Text),
                                                   codeManager.variableManager.PeekCounter()));
         codeManager.codeLines.Add(new ICPopParams(1));
     }
     if (x != -1)
     {
         codeManager.codeLines.Add(new ICAssignVarToVar(x, codeManager.variableManager.PeekCounter()));
     }
     else
     {
         var offset = codeManager.virtualTable.getOffset(codeManager.variableManager.ClassName, Id.Text);
         codeManager.codeLines.Add(new ICAssignVarToMem(0, codeManager.variableManager.PeekCounter(), offset));
     }
 }
예제 #3
0
        public override object Evaluate()
        {
            Complex value = LeftExpression.EvaluateAsComplex();
            Complex exp   = RightExpression.EvaluateAsComplex();

            return(Complex.Pow(value, 1.0 / exp));
        }
예제 #4
0
        public override object Evaluate()
        {
            double x = LeftExpression.EvaluateAsReal();
            double y = RightExpression.EvaluateAsReal();

            return((Complex)(x % y));
        }
예제 #5
0
        /// <summary>
        ///     Evaluates the expression.
        /// </summary>
        /// <param name="context">Evaluation context.</param>
        /// <returns>Expression result.</returns>
        protected override object EvaluateNode(LogEventInfo context)
        {
            var v1 = LeftExpression.Evaluate(context);
            var v2 = RightExpression.Evaluate(context);

            return(Compare(v1, v2, RelationalOperator));
        }
예제 #6
0
        public override object Evaluate()
        {
            double y = LeftExpression.EvaluateAsReal();
            double x = RightExpression.EvaluateAsReal();

            return((Complex)Math.Atan2(y, x));
        }
예제 #7
0
        public override object Evaluate()
        {
            IList <Complex> m1 = LeftExpression.EvaluateAsExpandableComplexArray();
            IList <Complex> m2 = RightExpression.EvaluateAsExpandableComplexArray();

            return(MathStats.Correlation(m1, m2));
        }
예제 #8
0
        public override object Evaluate()
        {
            IList <double> v = LeftExpression.EvaluateAsRealVector();

            if (RightExpression == Expression <Object> .Null)
            {
                return(new CMatrix(MathStats.Histogram(v)));
            }
            else
            {
                object intvals = RightExpression.Evaluate();
                if (intvals is Complex)
                {
                    return(new CMatrix(MathStats.Histogram(v, ExpressionExtensions.AsInt32((Complex)intvals))));
                }
                else if (intvals is CMatrix)
                {
                    return(new CMatrix(MathStats.Histogram(v, ExpressionExtensions.AsRealVector((CMatrix)intvals))));
                }
                else
                {
                    throw ExceptionHelper.ThrowWrongArgumentType(intvals);
                }
            }
        }
        public override object Evaluate()
        {
            CPolynomial poly  = LeftExpression.EvaluateAsCPolynomial();
            int         order = RightExpression.EvaluateAsInt32();

            return(new CMatrix(poly.NthDerivative(order).ToArray()));
        }
예제 #10
0
        public override object Evaluate()
        {
            CMatrix m     = LeftExpression.EvaluateAsCMatrix();
            int     order = RightExpression.EvaluateAsInt32();

            return(MathStats.PopulationCentralMoment(m, order));
        }
예제 #11
0
        public override object Evaluate()
        {
            CPolynomial poly1 = LeftExpression.EvaluateAsCPolynomial();
            CPolynomial poly2 = RightExpression.EvaluateAsCPolynomial();

            return(new CMatrix(CPolynomial.Modulus(poly1, poly2).ToArray()));
        }
예제 #12
0
        public override object Evaluate()
        {
            IList <double> xValues = LeftExpression.EvaluateAsRealVector();
            IList <double> yValues = RightExpression.EvaluateAsRealVector();

            return(new CMatrix(CPolynomial.InterpolatingPolynomial(xValues, yValues).ToArray()));
        }
예제 #13
0
            public override double Evaluate()
            {
                double left  = LeftExpression.Evaluate();
                double right = RightExpression.Evaluate();

                return(left + Random.NextDouble() * (right - left));
            }
예제 #14
0
        public override object Evaluate()
        {
            double r     = LeftExpression.EvaluateAsReal();
            double theta = RightExpression.EvaluateAsReal();

            return(new CMatrix(CoordSysConverter.PolarToCartesian(r, theta)));
        }
            public override Object Evaluate()
            {
                object left  = LeftExpression.Evaluate();
                object right = RightExpression.Evaluate();

                if (left is Complex)
                {
                    if (right is Complex)
                    {
                        return(EvaluateComplexComplex((Complex)left, (Complex)right));
                    }
                    else
                    {
                        throw ThrowWrongArgumentType("^");
                    }
                }
                else if (left is CMatrix)
                {
                    if (right is Complex)
                    {
                        return(EvaluateCMatrixComplex((CMatrix)left, (Complex)right));
                    }
                    else
                    {
                        throw ThrowWrongArgumentType("^");
                    }
                }
                else
                {
                    throw ThrowWrongArgumentType("^");
                }
            }
예제 #16
0
        public override string AsString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(");
            sb.Append(LeftExpression.ToString());
            switch (BinaryOperator)
            {
            case ExpressionBinaryOperator.AND: sb.Append(" AND "); break;

            case ExpressionBinaryOperator.OR: sb.Append(" OR "); break;

            case ExpressionBinaryOperator.EQUALS: sb.Append(" EQUALS "); break;

            case ExpressionBinaryOperator.NOTEQUALS: sb.Append(" NOTEQUALS "); break;

            case ExpressionBinaryOperator.LESSTHAN: sb.Append(" LESSTHAN "); break;

            case ExpressionBinaryOperator.GREATERTHAN: sb.Append(" GREATERTHAN "); break;

            case ExpressionBinaryOperator.PLUS: sb.Append(" PLUS "); break;

            case ExpressionBinaryOperator.MINUS: sb.Append(" MINUS "); break;

            case ExpressionBinaryOperator.TIMES: sb.Append(" TIMES "); break;

            case ExpressionBinaryOperator.DIVIDEDBY: sb.Append(" DIVIDEDBY "); break;
            }
            sb.Append(RightExpression.ToString());
            sb.Append(")");
            return(sb.ToString());
        }
예제 #17
0
        public override object Evaluate()
        {
            double x = LeftExpression.EvaluateAsReal();
            double y = RightExpression.EvaluateAsReal();

            return(new CMatrix(CoordSysConverter.CartesianToPolar(x, y)));
        }
예제 #18
0
        private static Rule GetRule(LeftExpression leftExpression, RightExpression rightExpression)
        {
            var rule = new Rule(leftExpression.View);

            rule.Initialize(leftExpression, rightExpression);
            return(rule);
        }
예제 #19
0
        public ValueExpression Evaluate()
        {
            var leftValue  = LeftExpression.Evaluate().Value;
            var rightValue = RightExpression.Evaluate().Value;

            switch (Operator)
            {
            case Operator.Plus:     return(new ValueExpression {
                    Value = leftValue + rightValue
                });

            case Operator.Minus:    return(new ValueExpression {
                    Value = leftValue - rightValue
                });

            case Operator.Asterisk: return(new ValueExpression {
                    Value = leftValue * rightValue
                });

            case Operator.Slash:    return(new ValueExpression {
                    Value = leftValue / rightValue
                });
            }

            throw new InvalidOperationException();
        }
        /// <summary>
        /// Evaluates the expression.
        /// </summary>
        /// <param name="context">Evaluation context.</param>
        /// <returns>Expression result.</returns>
        protected override object EvaluateNode(LogEventInfo context)
        {
            object v1 = LeftExpression.Evaluate(context);
            object v2 = RightExpression.Evaluate(context);

            return(Compare(v1, v2, RelationalOperator) ? BoxedTrue : BoxedFalse);
        }
        public override object Evaluate()
        {
            double rate = LeftExpression.EvaluateAsReal();
            double x    = RightExpression.EvaluateAsReal();

            return((Complex) new ExponentialDistribution(rate).CumulativeDistributionFunction(x));
        }
        public override object Evaluate()
        {
            double rate = LeftExpression.EvaluateAsReal();
            double x    = RightExpression.EvaluateAsReal();

            return((Complex) new ExponentialDistribution(rate).ProbabilityDensityFunction(x));
        }
        public override object Evaluate()
        {
            double a = LeftExpression.EvaluateAsReal();
            double b = RightExpression.EvaluateAsReal();

            return((Complex) new UniformDistribution(a, b).GetRandomVariable(_random));
        }
 public override string Template()
 {
     return($"{LeftExpression.Template()}" +
            "\nmovq\t%rax,%rcx" +
            $"\n{RightExpression.Template()}" +
            $"\n{AssignmentTemplate}\t# assign {RightExpression} to {LeftExpression}" +
            $"\n{LeftExpression.Save()}");
 }
 public override int Evaluate()
 {
     if (RightExpression.Evaluate() == 0)
     {
         throw new DivideByZeroException("divide by zero exception");
     }
     return(LeftExpression.Evaluate() / RightExpression.Evaluate());
 }
예제 #26
0
 public override bool Eval(PCBObject Obj)
 {
     if (LeftExpression.Eval(Obj) == true)
     {
         return(true);
     }
     return(RightExpression.Eval(Obj));
 }
예제 #27
0
        public override object Evaluate()
        {
            int rows = LeftExpression.EvaluateAsInt32();
            int cols = RightExpression.EvaluateAsInt32();

            PerformanceManager.Current.EnsureAcceptableArraySize(rows * cols);

            return(new CMatrix(rows, cols));
        }
예제 #28
0
            private Margin GetMargin(LeftExpression leftExpression, RightExpression rightExpression)
            {
                if (rightExpression.Constant == null)
                {
                    return(new Margin());
                }
                // assumes all constants are in Dp
                var constantPx = DpToPx(leftExpression.View.Context, rightExpression.Constant.Value);

                switch (leftExpression.Position)
                {
                case Position.Top:
                    return(new Margin {
                        Top = constantPx
                    });

                case Position.Baseline:
                    return(new Margin {
                        Top = constantPx
                    });

                case Position.Right:
                    return(new Margin {
                        Right = -constantPx
                    });

                case Position.Bottom:
                    return(new Margin {
                        Bottom = -constantPx
                    });

                case Position.Left:
                    return(new Margin {
                        Left = constantPx
                    });

                case Position.Width:
                    return(new Margin());

                case Position.Height:
                    return(new Margin());

                case Position.CenterX:
                    return(constantPx > 0 ?
                           new Margin {
                        Left = constantPx
                    } :
                           new Margin()
                    {
                        Right = -constantPx
                    });

                default:
                    throw new ArgumentException($"Constant expressions with {rightExpression.Position} are currently unsupported.");
                }
            }
예제 #29
0
 public void Initialize(LeftExpression leftExpression, RightExpression rightExpression)
 {
     if (!rightExpression.IsParent)
     {
         RelativeToViewId = rightExpression.Id;
     }
     SetMargin(leftExpression, rightExpression);
     SetLayoutRule(leftExpression, rightExpression);
     SetHeightWidth(leftExpression, rightExpression);
 }
예제 #30
0
 public override string Template()
 {
     return
         ($"{LeftExpression.Template()}" +
          "\npush\t%rax" +
          $"\n{RightExpression.Template()}" +
          "\nmovq\t%rax,%rbx" +
          "\npop\t%rax" +
          "\ncqo" +
          $"\n{BinaryTemplate}");
 }