Esempio n. 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string str = (string)((Button)e.OriginalSource).Content;

            if (str == "CL")
            {
                OutputlaLabel.Content = "";
                HEXlabel.Content      = "";
                DEClabel.Content      = "";
                OCTlabel.Content      = "";
                BINlabel.Content      = "";
            }


            else if (str == "=")
            {
                double res = new Expression(OutputlaLabel.Content.ToString()).calculate();
                OutputlaLabel.Content = res;
                HEXlabel.Content      = Conv(10, 16, res.ToString());
                DEClabel.Content      = Conv(10, 10, res.ToString());
                OCTlabel.Content      = Conv(10, 8, res.ToString());
                BINlabel.Content      = Conv(10, 2, res.ToString());
            }
            else
            {
                OutputlaLabel.Content += str;
            }
        }
Esempio n. 2
0
 public void Calculate()
 {
     try
     {
         org.mariuszgromada.math.mxparser.Expression calculation;
         calculation = new org.mariuszgromada.math.mxparser.Expression(FormulaLbl); //5*60
         Result      = calculation.calculate().ToString();                          //300
     }
     catch (Exception e)
     {
     }
 }
Esempio n. 3
0
        private string AssesExpresion()
        {
            string result = new Expression(MainWindow.LabelOutput.Text).calculate().ToString();

            if (result == "NaN")
            {
                return("NaN");
            }
            MainWindow.IntermediaryResults.Text = $"{MainWindow.LabelOutput.Text} =  {result}";
            return(result);

/*
 *          MainWindow.LabelOutput.CaretIndex = MainWindow.LabelOutput.Text.Length;
 */
        }
Esempio n. 4
0
        private void Entrée_Click(object sender, RoutedEventArgs e)
        {
            // gérer les caractères spéciaux
            resultatAffiche = true;

            string calculUtilisateur = mvm.NbInUser;
            string calcul            = mvm.NbInUser;

            calcul = calcul.Replace(" ", "");
            calcul = calcul.Replace("x", "*");
            calcul = calcul.Replace("√", "sqrt");
            calcul = calcul.Replace("²", "^2");
            calcul = calcul.Replace("%", "mod(");

            Console.WriteLine(calcul);

            org.mariuszgromada.math.mxparser.Expression exp = new org.mariuszgromada.math.mxparser.Expression(calcul);

            string resultat = Convert.ToString(exp.calculate());

            if (resultat.Equals("NaN"))
            {
                resultat = "Erreur de syntaxe";
                // resultat = "Erreur de syntaxe dans le calcul :\n" + calcul;
            }
            else
            {
                historique.Add(new KeyValuePair <string, string>(calculUtilisateur, resultat));
                mvm.AffichagesHistoriqueCalcAD = historiqueToString(historique)[0];
                mvm.AffichagesHistoriqueResAD  = historiqueToString(historique)[1];
                mvm.AffichagesHistoriqueCalcD  = historiqueToString(historique)[2];
                mvm.AffichagesHistoriqueResD   = historiqueToString(historique)[3];

                Console.WriteLine(mvm.historiqueObservable);

                mvm.historiqueObservable.Add(calculUtilisateur);
                mvm.historiqueObservable.Add(resultat);

                // Console.WriteLine(historique);
            }

            resultat = resultat.Replace(",", ".");

            mvm.StrAffichageTbx = resultat;

            // Console.WriteLine(calcul);
        }
Esempio n. 5
0
        private static async Task CmdMath(DiscordCommandArguments args)
        {
            string math = args["math"];

            org.mariuszgromada.math.mxparser.Expression expr = new org.mariuszgromada.math.mxparser.Expression(math);
            StringBuilder sb = new StringBuilder();

            if (!expr.checkSyntax())
            {
                sb.AppendLine($"{args.User.Mention} - Error in mathematical expression:");
                sb.AppendLine(expr.getErrorMessage());
            }
            else
            {
                sb.AppendLine($"{args.User.Mention} - {math} = **{expr.calculate()}**");
            }
            await args.Channel.SendMessage(sb.ToString());
        }
Esempio n. 6
0
        string AssesExpresionAndAddToList()
        {
            string result = new Expression(MainWindow.LabelOutput.Text).calculate().ToString();

            if (result == "NaN")
            {
                return("NaN");
            }
            Label label = new Label
            {
                Content             = $"{MainWindow.LabelOutput.Text} = {result}",
                HorizontalAlignment = HorizontalAlignment.Right,
                Foreground          = Brushes.CadetBlue
            };

            MainWindow.ListView.Items.Add(label);
            MainWindow.ListView.ScrollIntoView(label);
            MainWindow.IntermediaryResults.Text = "";
            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// Evaluate the Result and display text
        /// </summary>
        /// <returns>The history to display if length is 0 should be discarded</returns>
        public String EvaluateResult()
        {
            string evaluatedText = _display.Text;

            //have to use fullnamespace as it conflicts with another windows defined expression:(
            org.mariuszgromada.math.mxparser.Expression expression = new org.mariuszgromada.math.mxparser.Expression(evaluatedText);
            double result = expression.calculate();

            _OverWrite = true;

            if (Double.IsNaN(result))
            {
                _display.Text = "Error";
            }
            else
            {
                _display.Text = result.ToString();
                return(evaluatedText + "=" + result.ToString());
            }
            return("");
        }
Esempio n. 8
0
 public Task solve([Remainder] string equation)
 {
     org.mariuszgromada.math.mxparser.Expression expression = new org.mariuszgromada.math.mxparser.Expression(equation);
     return(Context.Channel.SendMessageAsync(expression.calculate().ToString()));
 }
        /// <summary>
        /// Wandelt Sonderzeichen in der Rechenzeichenkette in für das Rechenframework lesbare ausdrücke um
        /// und schickt den umgewandelten String weiter an den ExpressionEvaluator.
        /// </summary>
        private void Calculate()
        {
            List <string> preParse    = new List <string>();
            int           pos         = 0;
            double        parsedToken = 0;

            foreach (var token in calculation)
            {
                if (double.TryParse(token, out parsedToken))
                {
                    preParse.Add(parsedToken.ToString().Replace(",", "."));
                }
                else
                {
                    switch (token)
                    {
                    case "ANS":
                        preParse.Add(lastResult.ToString().Replace(",", "."));
                        break;

                    case "EXP":
                        preParse.Add("E");
                        break;

                    case "𝞹":
                        preParse.Add(Math.PI.ToString().Replace(",", "."));
                        break;

                    case "×":
                        preParse.Add("*");
                        break;

                    case "÷":
                        preParse.Add("/");
                        break;

                    case ",":
                        preParse.Add(".");
                        break;

                    default:
                        preParse.Add(token);
                        break;
                    }
                }
                pos = preParse.Count;
            }

            var    parsedOutputString = string.Join("", preParse.ToArray());
            var    expression         = new org.mariuszgromada.math.mxparser.Expression(parsedOutputString);
            double result             = ExpressionEvaluator.EvaluateStringExpression(parsedOutputString);

            lastResult = result;

            pastCalculations.Add(new CalculatorExpression {
                Calculation = calculation.ToArray()
            });
            calculation.Clear();
            calculation.Add(result.ToString());
            UpdateCalculationText();
            txtCalculation.Focus();
        }
Esempio n. 10
0
        static void FormulaGenerator()
        {
            char[]        chars                      = new char[] { '+', '-', '*', '/', '^' };
            char[]        letters                    = new char[] { 'x', 'y', 'z' };
            string        generatedFormula           = "";
            string        generateFormulaWithLetters = "";
            StringBuilder build                      = new StringBuilder();
            Random        r;
            string        result           = "";
            string        resultWithLetter = "";

            for (int i = 0; i < 10; i++)
            {
                r = new Random();

                generatedFormula           = r.Next(1, 100).ToString() + chars[r.Next(chars.Length)] + "(" + r.Next(1, 100).ToString() + chars[r.Next(chars.Length)] + r.Next(1, 100).ToString() + ")" + chars[r.Next(chars.Length)] + r.Next(1, 100).ToString() + chars[r.Next(chars.Length)] + r.Next(1, 100).ToString();
                generateFormulaWithLetters = r.Next(1, 100).ToString() + chars[r.Next(chars.Length)] + letters[r.Next(letters.Length)] + chars[r.Next(chars.Length)] + "(" + r.Next(1, 100).ToString() + chars[r.Next(chars.Length)] + r.Next(1, 100).ToString() + ")" + chars[r.Next(chars.Length)] + r.Next(1, 100).ToString() + chars[r.Next(chars.Length)] + r.Next(1, 100).ToString();
                try
                {
                    org.mariuszgromada.math.mxparser.Expression formula            = new org.mariuszgromada.math.mxparser.Expression(generatedFormula);
                    org.mariuszgromada.math.mxparser.Expression formulaWithLetters = new org.mariuszgromada.math.mxparser.Expression(generateFormulaWithLetters);
                    result           = formula.calculate().ToString();
                    resultWithLetter = formulaWithLetters.calculate().ToString();


                    //if (!File.Exists(path))
                    //{
                    //    File.Create(path).Dispose();
                    //    using (TextWriter tw = new StreamWriter(path))
                    //    {
                    //        tw.WriteLine("The very first line!");
                    //        tw.Close();
                    //    }

                    //}

                    //else if (File.Exists(path))
                    //{
                    FileStream   fs = new FileStream("Results.txt", FileMode.Append);
                    StreamWriter sw = new StreamWriter(fs);

                    sw.WriteLine("Number " + i.ToString());
                    sw.WriteLine("\n" + "Formula : " + generatedFormula);
                    sw.WriteLine("Result : " + result + "\n");

                    sw.WriteLine();
                    sw.Close();
                    fs.Close();
                    //}

                    Console.WriteLine("Number " + i.ToString() + "\n" + "Formula : " + generatedFormula + "\n" + "Result : " + result + "\n" + "Condition " + true.ToString());
                    Console.WriteLine("Number " + i.ToString() + "\n" + "Formula : " + generateFormulaWithLetters + "\n" + "Result : " + resultWithLetter + "\n" + "Condition " + true.ToString());
                }
                catch (Exception e)
                {
                    generateFormulaWithLetters = e.ToString() + "false";
                }

                Thread.Sleep(1000);
            }
        }