private bool ContainsNaNHelper(MathFuncNode node)
        {
            for (int i = 0; i < node.Childs.Count; i++)
            {
                if (ContainsNaNHelper(node.Childs[i]))
                {
                    return(true);
                }
            }

            CalculatedNode calcNode = node as CalculatedNode;

            if (calcNode != null && double.IsNaN(calcNode.DoubleValue))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private MathFuncNode MakeSubstitution(MathFuncNode node)
        {
            int ind = -1;

            for (int j = 0; j < LeftNode.Childs.Count; j++)
            {
                if (LeftNode.Childs[j].Name == node.Name)
                {
                    ind = j;
                    break;
                }
            }
            if (ind != -1)
            {
                if (_currentFunc.Childs[ind].IsTerminal)
                {
                    return(_currentFunc.Childs[ind]);
                }
                else
                {
                    return(new FuncNode((FuncNode)_currentFunc.Childs[ind]));
                }
            }

            MathFuncNode result;

            switch (node.Type)
            {
            case MathNodeType.Calculated:
                result = new CalculatedNode(((CalculatedNode)node).Value);
                break;

            case MathNodeType.Value:
                result = new ValueNode((ValueNode)node);
                break;

            case MathNodeType.Constant:
            case MathNodeType.Variable:
                result = node;
                break;

            default:
            case MathNodeType.Function:
                result = ((FuncNode)node).FunctionType != null ?
                         new FuncNode((KnownFuncType)((FuncNode)node).FunctionType) :
                         new FuncNode(node.Name);
                break;
            }

            for (int i = 0; i < node.Childs.Count; i++)
            {
                switch (node.Childs[i].Type)
                {
                case MathNodeType.Calculated:
                    result.Childs.Add(new CalculatedNode((CalculatedNode)node.Childs[i]));
                    break;

                case MathNodeType.Value:
                    result.Childs.Add(new ValueNode((ValueNode)node.Childs[i]));
                    break;

                case MathNodeType.Constant:
                case MathNodeType.Variable:
                    result.Childs.Add(node.Childs[i]);
                    break;

                case MathNodeType.Function:
                    result.Childs.Add(MakeSubstitution((FuncNode)node.Childs[i]));
                    break;
                }
            }
            return(result);
        }
 public CalculatedNode(CalculatedNode node)
 {
     Value = node.Value;
     Name  = Value.ToString(CultureInfo.InvariantCulture);
 }
		private MathFuncNode MakeSubstitution(MathFuncNode node)
		{
			int ind = -1;
			for (int j = 0; j < LeftNode.Childs.Count; j++)
				if (LeftNode.Childs[j].Name == node.Name)
				{
					ind = j;
					break;
				}
			if (ind != -1)
			{
				if (_currentFunc.Childs[ind].IsTerminal)
					return _currentFunc.Childs[ind];
				else
					return new FuncNode((FuncNode)_currentFunc.Childs[ind]);
			}

			MathFuncNode result;
			switch (node.Type)
			{
				case MathNodeType.Calculated:
					result = new CalculatedNode(((CalculatedNode)node).Value);
					break;
				case MathNodeType.Value:
					result = new ValueNode((ValueNode)node);
					break;
				case MathNodeType.Constant:
				case MathNodeType.Variable:
					result = node;
					break;
				default:
				case MathNodeType.Function:
					result = ((FuncNode)node).FunctionType != null ?
						new FuncNode((KnownFuncType)((FuncNode)node).FunctionType) :
						new FuncNode(node.Name);
					break;
			}

			for (int i = 0; i < node.Childs.Count; i++)
				switch (node.Childs[i].Type)
				{
					case MathNodeType.Calculated:
						result.Childs.Add(new CalculatedNode((CalculatedNode)node.Childs[i]));
						break;
					case MathNodeType.Value:
						result.Childs.Add(new ValueNode((ValueNode)node.Childs[i]));
						break;
					case MathNodeType.Constant:
					case MathNodeType.Variable:
						result.Childs.Add(node.Childs[i]);
						break;
					case MathNodeType.Function:
						result.Childs.Add(MakeSubstitution((FuncNode)node.Childs[i]));
						break;
				}
			return result;
		}
        private MathFuncNode MakeSubstitution(MathFuncNode node)
        {
            int ind = -1;

            for (int j = 0; j < LeftNode.Children.Count; j++)
            {
                if (LeftNode.Children[j].Name == node.Name)
                {
                    ind = j;
                    break;
                }
            }
            if (ind != -1)
            {
                if (_currentFunc.Children[ind].IsTerminal)
                {
                    return(_currentFunc.Children[ind]);
                }
                else
                {
                    return(new FuncNode((FuncNode)_currentFunc.Children[ind]));
                }
            }

            MathFuncNode result = null;

            switch (node)
            {
            case CalculatedNode calculatedNode:
                result = new CalculatedNode(calculatedNode.Value);
                break;

            case ValueNode valueNode:
                result = new ValueNode(valueNode);
                break;

            case ConstNode constNode:
            case VarNode varNode:
                result = node;
                break;

            case FuncNode funcNode:
                result = funcNode.FunctionType != null ?
                         new FuncNode((KnownFuncType)funcNode.FunctionType) :
                         new FuncNode(node.Name);
                break;
            }

            for (int i = 0; i < node.Children.Count; i++)
            {
                switch (node.Children[i])
                {
                case CalculatedNode calculatedNode:
                    result.Children.Add(new CalculatedNode(calculatedNode));
                    break;

                case ValueNode valueNode:
                    result.Children.Add(new ValueNode(valueNode));
                    break;

                case ConstNode constNode:
                case VarNode varNode:
                    result.Children.Add(node.Children[i]);
                    break;

                case FuncNode funcNode:
                    result.Children.Add(MakeSubstitution(funcNode));
                    break;
                }
            }
            return(result);
        }
Пример #6
0
		public CalculatedNode(CalculatedNode node)
		{
			_value = node.Value;
			Name = _value.ToString(CultureInfo.InvariantCulture);
		}