Example #1
0
        private List <Signal> BroadcastDivisionCalculate(List <Signal> values)
        {
            Signal leftSignal   = values[0];
            Signal rightSignal  = values[1];
            Signal outputSignal = Results[0];

            outputSignal.Clone(leftSignal.BroadcastDivide(rightSignal));
            return(Results);
        }
Example #2
0
        private object Visit(ValBinOpAST valBinOpAST)
        {
            Signal left  = new Signal(Visit(valBinOpAST.Left));
            Signal right = new Signal(Visit(valBinOpAST.Right));

            try
            {
                switch (valBinOpAST.Operator.Value)
                {
                case "+":
                    return((left + right).Unpack());

                case "-":
                    return((left - right).Unpack());

                case "*":
                    return((left * right).Unpack());

                case "/":
                    if (right.Unpack() is double v && v == 0)
                    {
                        throw logger.Error(new SemanticException(valBinOpAST.Right.FindToken(), "0 Division"));
                    }
                    return((left / right).Unpack());

                case "^":
                    return((left.RaiseToPower(right)).Unpack());

                case ".*":
                    return((left.BroadcastMultiply(right)).Unpack());

                case "./":
                    return((left.BroadcastDivide(right)).Unpack());

                case ".^":
                    return((left.BroadcastPower(right)).Unpack());

                default:
                    throw logger.Error(new SemanticException(valBinOpAST.FindToken(), "Invalid operator"));
                }
            }
            catch (LigralException)
            {
                throw logger.Error(new SemanticException(valBinOpAST.FindToken(), "Calculation fault"));
            }
            catch (System.Exception e)
            {
                throw logger.Error(new SemanticException(valBinOpAST.FindToken(), e.Message));
            }
        }