Exemplo n.º 1
0
        private void Derivate_Click(object sender, RoutedEventArgs e)
        {
            if (Function.Text.IndexOf('\\') != -1)
            {
                IsValidCheckBox.IsChecked = false;
                return;
            }
            if (!IsValid(Function.Text))
            {
                IsValidCheckBox.IsChecked = false;
                return;
            }
            IsValidCheckBox.IsChecked = true;
            MathExpression function   = Parse(Function.Text);
            MathExpression derivative = function.Root.Derivative(Variable.Text);

            Derivative.Text = derivative.ToString();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the resolved text where the expression have been evaluated, the resolved text is cached so do not worry about calling this multiple times
        /// </summary>
        /// <returns>The resolved text where the expression have been evaluated</returns>
        public string GetResolvedText()
        {
            if (resolvedTextNeedCache)
            {
                int start = SimpleText.IndexOf(OpeningExpressionDelimiter);
                int end   = SimpleText.IndexOf(ClosingExpressionDelimiter);

                if (start == -1)
                {
                    return(SimpleText);
                }

                double result = new MathExpression(SimpleText.Substring(start + 1, end - start - 1)).Evaluate();

                cachedResolvedText = SimpleText.Replace(SimpleText.Substring(start, end - start + 1), result.ToString(formatStr, CultureInfo.InvariantCulture));
            }

            return(cachedResolvedText);
        }
Exemplo n.º 3
0
 public void UnaryMinusTest1()
 {
     expr = new MathExpression("-2+3");
     Console.WriteLine(expr.ToString());
     Assert.AreEqual(1, expr.Calculate());
 }