Example #1
0
            public static string e(string input)
            {
                if (input.Length < 18)
                {
                    return(System.Math.Exp(double.Parse(input)).ToString().Replace(",", "."));
                }

                string res = "0";

                //string buf_fakt = "0";
                //string buf_div = "0";

                for (int i = 0; i < 25; i++)
                {
                    // buf_fakt = Fakt(i.ToString());
                    // buf_div = DivisionStringBETA(Expon(input, i.ToString()), buf_fakt);
                    //buf_div = DivisionStringBETA(Expon(input, i.ToString()), Fakt(i.ToString()) );

                    //                res = SumString(res, buf_div);

                    //res = SumString(res, DivisionStringBETA(Expon(input, i.ToString()), Fakt(i.ToString()) ));

                    //debug
                    //res = DivisionStringBETA(Expon(input, i.ToString()), Fakt(i.ToString()));

                    res = Math_v2.SumString(res, Math.DivisionStringBETA(IntegerExpon(input, i.ToString()), Fakt(i.ToString())));
                }

                return(res);
            }
Example #2
0
            public static string ExecuteOperation(string operation)
            {
                Regex keyWord = new Regex(@"e|sin|ln|tan|cos|cotg|sinh|cosh|tanh|^|arcsin|arccos");
                Regex num     = new Regex(@"[0-9+\.*0-9*]");

                if (operation.IndexOf('^') > 0)
                {
                    string num1 = operation.Remove(operation.IndexOf("^")),
                           num2 = operation.Remove(0, operation.IndexOf("^") + 1);

                    return(Math_v2.IntegerExpon(num1, num2));
                }

                switch (keyWord.Match(operation).Value)
                {
                case "sin":
                { return(Math_v2.Trigonometric.Sin(num.Match(operation).Value)); }

                case "cos":
                { return(Math_v2.Trigonometric.Cos(num.Match(operation).Value)); }

                case "tan":
                { return(Math_v2.Trigonometric.Tan(num.Match(operation).Value)); }

                case "arcsin":
                { return(Math_v2.Trigonometric.Arcsin(num.Match(operation).Value)); }

                case "arccos":
                { return(Math_v2.Trigonometric.Arccos(num.Match(operation).Value)); }

                case "arctan":
                { return(Math_v2.Trigonometric.Arctan(num.Match(operation).Value)); }

                case "ln":
                { return(Math_v2.Logaritmic.ln(num.Match(operation).Value)); }

                case "e":
                { return(Math_v2.Exponential.e(num.Match(operation).Value)); }
                }

                return(operation);
            }
Example #3
0
        public static string Fakt(string input)
        {
            if (Math_v2.EqualString(input, "1") == 0)
            {
                return("1");
            }
            if (Math_v2.EqualString(input, "0") == 0)
            {
                return("1");
            }
            else
            {
                //return ProductString(input, Fakt(DesumString(input, "1")));
                string ret = "1";
                for (string i = "1"; Math_v2.EqualString("<=", i, input); i = Math_v2.Inc1(i))
                {
                    ret = ProductString(ret, i);
                }

                return(ret);
            }
        }
Example #4
0
            public static string ExecuteOperation(string op1, string op2, string zn)
            {
                Regex keyWord = new Regex(@"sin|ln|tan|cos|cotg|sinh|cosh|tanh|^|arcsin|arccos");

                if (keyWord.IsMatch(op1))
                {
                    op1 = ExecuteOperation(op1);
                }
                if (keyWord.IsMatch(op2))
                {
                    op2 = ExecuteOperation(op2);
                }

                // osetrit promenne na vstupu
                if (zn == "+")
                {
                    return(Math_v2.SumString(op1, op2));
                }
                if (zn == "-")
                {
                    return(Math_v2.DesumString(op1, op2));
                }
                if (zn == "/")
                {
                    return(Math.DivisionStringBETA(op1, op2));
                }
                if (zn == "*")
                {
                    return(Math_v2.ProductString(op1, op2));
                }

                /*if (zn == "^")
                 *  return Math_v2.*/



                return("0");
            }
Example #5
0
        static void Main(string[] args)
        {
            Process currentProcess = Process.GetCurrentProcess();


            //Console.Write("{0}\n", Math.SumString("356", "658"));
            //Console.Write("{0}\n", Math.DesumString("356", "658"));
            //Console.Write("{0}\n", Math.DesumString("1100", "1092"));
            //Console.Write("{0}\n", Math.SumString("21.5", "23.18"));
            //Console.Write("{0}\n", Math.DesumString("2.1250", "8"));
            //Console.Write("{0}\n", Math.DesumString("0", "8"));
            //Console.Write("{0}\n", Math.DivisionStringBETA("2", ".5"));

            /*Console.Write("{0}\n\n",Math.ProductString("112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212",
             *      "32123321211200032123321211200032123321321233212112000321233212112000321233213212332121120003212332121120003212332132123321211200032123321211200032123321112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212"));
             *
             * Console.Write("{0}\n", Math.ProductStringBETA("112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212",
             *      "32123321211200032123321211200032123321321233212112000321233212112000321233213212332121120003212332121120003212332132123321211200032123321211200032123321112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212"));
             *
             * Console.Write("{0}\n", Math.DivisionStringBETA("112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212",
             *      "3212332121120003212332121120003212332132123321211200032123321211200032123321321233212112000321233212112000321233213212332121120003212332121120003212332111200032123321211200032123321211200032123321211200032123321211200032123321211200032123321211200032123321211200032123321211200032123321211200"));
             * */
            //Console.Write("{0}\n", Math.EqualString("22.55123135424", "22.5"));
            //Console.Write("{0}\n", Math.ProductString("1.352", "1000"));
            //Console.Write("{0}\n", Math.ProductString("0.2", "0.3"));
            //Console.Write("{0}\n", Math.DivisionString("1", "0.1250"));
            //Console.Write("{0}\n", Math.ConvertToRational("23", "8"));
            //Console.Write("{0}\n", Math.ConvertToRational("2.5"));
            //Console.Write("{0}\n", Math.DivisionStringBETA("1", "3"));
            //Console.Write("{0}\n", Math.ProductString("1236295", "2"));
            //Console.Write("{0}\n", Math.DesumString("2963640", "2472590"));
            //Console.Write("{0}\n", Math.DivisionStringBETA("15.32659", "12.36295")); //1,239719484
            //Console.Write("{0}\n", Math.DivisionStringBETA("12.36295121", "153.2659"));
            //Console.Write("{0}\n", Math.Sqrt("2", "900"));
            //Console.Write("[^\\\\]\".*[^\\\\]\"");
            //Console.Write("{0}\n", Math.DesumString("3.2", "3.155"));
            //Console.Write("{0}\n", Math.DesumString("3.0235294177", "0.023437863506"));
            //Console.Write("{0}\n", Math.Trigonometric.Sinus("50"));
            //Console.Write("{0}\n", Math.DivisionStringBETA(Math.pi, Math.e));
            //Console.Write("{0}\n", Math.GetPi());
            //Console.Write("{0}\n", Math.Expon("2", Math.DivisionString("1", "2", 0)));
            //Console.Write("{0}\n", Math.ProductString("112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212", Math.DesumString("11200032123321211200032123321211200032123321211200032123321211200032123321211200032123321211200032123321211200032123321211200032123321222432123166542132321", "1")));
            //Console.Write("{0}\n", Math.Fakt("1000"));
            //Console.Write("{0}\n", Math.Faktorial("1000"));
            //Console.Write("{0}\n", Math.ProductString( Math.ProductString("1000000", Math.DesumString("1000000", "1")),  Math.DesumString("1000000", "1")));
            //Console.Write("{0}\n", Math.Degree("1°63°0°"));          // - doladit
            //Console.Write("{0}\n", Math.EqualString("=", "10", "10"));
            //Console.Write("{0}\n", Math.CleanString("0100"));
            //Console.Write("{0}\n", Math.DivisionStringBETA("0.0875", Math.DivisionStringBETA("1", "100")));
            //Console.Write("{0}\n", Math.ConvertToRational("2.785"));// - doladit
            //Console.Write("{0}\n", Math.SumString("18.5", "20.8333333333333333333333333333"));
            //Console.Write("{0}\n", Math.SumString("18.50", "20.83"));
            //Console.Write("{0}\n", Math.Exponential.e("5"));// - doladit
            //Console.Write("{0}\n", Math.SumString("1.99999999999999999999999999", "0.1111111111111111111111111111"));
            //Console.Write("{0}\n", Math.SumString("1.9", "0.1"));
            //Console.Write("{0}\n", Math.DivisionStringBETA("8965.5868", "651.9855"));
            //Console.Write("{0}\n", Math_v2.SumString("39.333333333333333333333333", "26.04166666666666666666"));
            //Console.Write("{0}\n", Math.ProductString("1236295", "2"));
            //Console.Write("{0}\n", Math_v2.ProductString("1236295", "2"));

            //Console.Write("{0}\n", Math.DesumString("3.0235294177", "0.023437863506"));
            //Console.Write("{0}\n", Math_v2.DesumString("3.0235294177", "0.023437863506"));
            //Console.Write("{0}\n", Math.DivisionStringBETA("12.36295121", "153.2659"));
            //Console.Write("{0}\n", Math_v2.DivisionString("12.36295121", "153.2659"));
            //Console.Write("∞");


            //Console.Write("{0}\n", Math_v2.Trigonometric.Sin("5"));
            //ParserTree.Tree test = new ParserTree.Tree("3+(5*4+3)*5.5*(5+2*(3+3*(4+5))*(3+5))");
            //ParserTree.Tree test2 = new ParserTree.Tree("3+sin 3*(6+7)*6+8+2*6*5+7");
            //Console.WriteLine("{0}", test2.GetResult());
            //Console.WriteLine("{0}", Math_v2.DegreeToNumber("57°30'10\""));
            //Console.WriteLine("{0}", Math_v2.RadianToDegree("1.23"));
            //Console.WriteLine("{0}", Math_v2.NumberToDegree(Math_v2.RadianToDegree("1.23")));
            //Console.WriteLine("{0}", Math_v2.Trigonometric.Sin(Math_v2.DegreeToRad("57°30\"")));
            //Console.WriteLine("{0}", Math_v3.Fakt("1000"));

            MathNumber mn1 = new MathNumber("1254313210");
            MathNumber mn2 = new MathNumber("75128562");

            Console.WriteLine("{0}", mn1 + mn2);

            //Console.Write("{0}\n", test.GetResult());
            //string op1 = "1120003212332121120003212332121120003212332121.12000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000",
            //    op2 = "1120003212332121120003212332121120003212332121.12000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000";

            /** /string[,] op1 = { { "1", "2", "3" }, { "1", "2", "3" }, { "1", "2", "3"} , { "1", "2", "3" } },
             *  op2 = { { "1", "2", "3", "4" }, { "1", "2", "3", "4" }, { "1", "2", "3", "4" } };
             *
             * string [,] res = Math_v2.Matrix.MatrixProductString(op1, op2);
             *
             * for (int i = 0; i < res.GetLength(0); i++)
             * {
             *  for (int j = 0; j < res.GetLength(1); j++)
             *  {
             *      Console.Write("{0}\t", res[i, j]);
             *  }
             *  Console.Write("\n");
             * }/**/


            //Console.Write("{0}\n", Math_v2.Ackermann("1", "3"));

            /*Console.Write("{0}\n", Math_v2.EqualString("==", Math_v3.ProductString(op1, op2),
             *                                              Math_v2.ProductString(op1, op2)));
             *
             * /*Console.Write("{0}\n", Math_v2.EqualString("==", Math_v2.ProductString(op1, op2),
             *                                              Math.ProductString(op1, op2)));
             * /* */
            int iy = 0;



            /*  //debugovaci merici proces
             * int pocet_kroku = 3000;
             * currentProcess.Refresh();
             * TimeSpan start = currentProcess.TotalProcessorTime;
             * for (int i = 0; i < pocet_kroku; i++)
             *  Math.DesumString("112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000",
             *      "112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000");
             * currentProcess.Refresh();
             * double seconds = (currentProcess.TotalProcessorTime - start).TotalMilliseconds;
             *
             * currentProcess.Refresh();
             * TimeSpan start2 = currentProcess.TotalProcessorTime;
             * for (int i = 0; i < pocet_kroku; i++)
             *  Math_v2.DesumString("112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000",
             *      "112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000321233212112000");
             * currentProcess.Refresh();
             * double seconds2 = (currentProcess.TotalProcessorTime - start2).TotalMilliseconds;
             *
             *
             * Console.Write("Meření času(rozdil)\nMathV1 : {0} ms.\nMathV2 : {1} ms\n", seconds, seconds2);
             * /* */

            /*//debugovaci merici proces
             * int pocet_kroku = 50000;
             * currentProcess.Refresh();
             * TimeSpan start3 = currentProcess.TotalProcessorTime;
             * for (int i = 0; i < pocet_kroku; i++)
             *  Math.ProductString("1356385",
             *      "1356385");
             * currentProcess.Refresh();
             * double seconds3 = (currentProcess.TotalProcessorTime - start3).TotalMilliseconds;
             *
             * currentProcess.Refresh();
             * TimeSpan start4 = currentProcess.TotalProcessorTime;
             * for (int i = 0; i < pocet_kroku; i++)
             *  Math_v2.ProductString("1356385",
             *      "1356385");
             * currentProcess.Refresh();
             * double seconds4 = (currentProcess.TotalProcessorTime - start4).TotalMilliseconds;
             *
             * currentProcess.Refresh();
             * TimeSpan start5 = currentProcess.TotalProcessorTime;
             * for (int i = 0; i < pocet_kroku; i++)
             *  Math_v3.ProductString("1356385",
             *      "1356385");
             * currentProcess.Refresh();
             * double seconds5 = (currentProcess.TotalProcessorTime - start5).TotalMilliseconds;
             *
             *
             * Console.Write("Meření času(součet)\nMathV11 : {0} ms.\nMathV2 : {1} ms\nMathV3 : {2}\n", seconds3, seconds4, seconds5);
             * /* */

            //*//debugovaci merici proces
            string[] res = new string[6];

            //int pocet_kroku = 50000;
            int pocet_kroku = 10000;

            var num1 = "446744073709551614467440737095516144674407370955161446744073709551614467440737095516144674407370955161.001200003003021000000654";
            var num2 = "46744073709551614467440737095516144674407370955161446744073709551614467440737095516144674407370955161.1200003003021000000654";

            //var num1 = "446744073709551614467440737095516144674407370955161446744073709551614467440737095516144674407370955161";
            //var num2 = "46744073709551614467440737095516144674407370955161446744073709551614467440737095516144674407370955161";

            //num2 = "15";


            double seconds4 = testPefrormance(() =>
            {
                return(() => res[0] = Math.SumString(num1, num2));
            });


            double seconds5 = testPefrormance(() =>
            {
                return(() => res[1] = Math_v2.SumString(num1, num2));
            });

            double seconds6 = testPefrormance(() =>
            {
                return(() => res[2] = Math_v2.SumString(num1, num2, false));
            });


            double seconds7 = testPefrormance(() =>
            {
                return(() => res[3] = Math_v4.SumString(num1, num2));
            });


            double seconds8 = testPefrormance(() =>
            {
                MathNumber m1 = MathNumber.Parse(num1);
                MathNumber m2 = MathNumber.Parse(num2);

                return(() => res[4] = (m1 + m2).ToString());
            });

            //currentProcess.Refresh();
            //TimeSpan start9 = currentProcess.TotalProcessorTime;
            //BigInteger bi_t1 = BigInteger.Parse("446744073709551614467440737095516144674407370955161446744073709551614467440737095516144674407370955161");
            //BigInteger bi_t2 = BigInteger.Parse("446744073709551614467440737095516144674407370955161446744073709551614467440737095516144674407370955161");

            //for (int i = 0; i < pocet_kroku; i++)
            //    res[5] = (bi_t1 + bi_t2).ToString();
            //currentProcess.Refresh();
            //double seconds9 = (currentProcess.TotalProcessorTime - start9).TotalMilliseconds;

            double seconds9 = 0;

            //double seconds9 = testPefrormance(() =>
            //{
            //    var m1 = BigInteger.Parse(num1);
            //    var m2 = BigInteger.Parse(num2);

            //    return () => res[5] = (m1 + m2).ToString();
            //});

            Console.WriteLine("Meření času(soucin)\nMathV1 : {3} ms\nMathV2 : {0} ms. with convert\nMathV2 : {1} ms\nMathV4 : {2} ms\nMathV4 : {4} ms, MathNumber Class\nBigInt : {5} ms\n", seconds5, seconds6, seconds7, seconds4, seconds8, seconds9);
            for (int i = 0; i < res.Length; i++)
            {
                Console.Write("MathV{0} : {1}\n", i + 1, res[i]);
            }
            /* */


            /* //debugovaci merici proces
             * int pocet_kroku = 1;
             * currentProcess.Refresh();
             * TimeSpan start7 = currentProcess.TotalProcessorTime;
             * for (int i = 0; i < pocet_kroku; i++)
             *  Math_v2.Fakt("4000");//,
             *      //"4225");
             * currentProcess.Refresh();
             * double seconds7 = (currentProcess.TotalProcessorTime - start7).TotalMilliseconds;
             *
             * currentProcess.Refresh();
             * TimeSpan start8 = currentProcess.TotalProcessorTime;
             * for (int i = 0; i < pocet_kroku; i++)
             *  Math_v3.Fakt("4000");//,
             *      //"4225");
             * currentProcess.Refresh();
             * double seconds8 = (currentProcess.TotalProcessorTime - start8).TotalMilliseconds;
             *
             *
             *
             * Console.Write("Meření času(faktorial)\nMathV2 : {0} ms.\nMathV3 : {1} ms\n", seconds7, seconds8);
             * /* */
        }
Example #6
0
        public static string ProductString(string op1, string op2)
        {
            int       znamenko   = 0;
            const int FOR_LENGTH = 8;

            if (!IsInteger(op1) || !IsInteger(op2))
            {
                znamenko  = DeletePoint(ref op1);
                znamenko += DeletePoint(ref op2);
            }

            // konzistence nasobeni
            if (op2.Length > op1.Length)
            {
                string buf = op1;
                op1 = op2;
                op1 = buf;
            }

            if (op1.Length > FOR_LENGTH && op2.Length <= FOR_LENGTH)
            {
                string[] ops = new string[op1.Length / FOR_LENGTH + 1];

                for (int i = 0; i < op1.Length / FOR_LENGTH + 1; i++)
                {
                    ops[i] = op1.Remove(0, i * FOR_LENGTH);
                    //if (op1.Length/8 != i)
                    if (ops[i].Length > FOR_LENGTH)
                    {
                        ops[i] = ops[i].Remove(FOR_LENGTH);
                    }
                }
                StringBuilder res     = new StringBuilder();
                ulong         go_next = 0;

                for (int i = ops.Length - 1; i >= 0; i--)
                {
                    if (ops[i] != "")
                    {
                        ulong  resi = ulong.Parse(ops[i]) * ulong.Parse(op2) + go_next;
                        string res2 = resi.ToString();

                        if (res2.Length > ops[i].Length)
                        {
                            if (i == 0)
                            {
                                res.Insert(0, res2);
                            }
                            else
                            {
                                go_next = ulong.Parse(res2.Remove(res2.Length - ops[i].Length));
                                res.Insert(0, res2.Remove(0, res2.Length - ops[i].Length));
                            }
                        }
                        else
                        {
                            res.Insert(0, res2);
                            //doplneni nulama
                            for (int ii = 0; ii < FOR_LENGTH - res2.Length; ii++)
                            {
                                if (i != 0)
                                {
                                    res.Insert(0, "0");
                                }
                            }
                            go_next = 0;
                        }
                    }
                }

                if (znamenko > 0)
                {
                    res.Insert(res.Length - znamenko, ".");
                }
                return(res.ToString());
            }
            else if (op1.Length <= FOR_LENGTH && op2.Length <= FOR_LENGTH)
            {
                string res = (ulong.Parse(op1) * ulong.Parse(op2)).ToString();
                if (znamenko > 0)
                {
                    return(res.Insert(res.Length - znamenko, "."));
                }
                return(res);
            }

            else
            {
                return(Math_v2.ProductString(op1, op2));

                /*StringBuilder[] scitance = AppendZero(op2.Length);
                 * ulong[] go_next = new ulong[op1.Length / FOR_LENGTH];
                 * string[] ops1 = new string[op1.Length / FOR_LENGTH];
                 * string[] ops2 = new string[op2.Length / FOR_LENGTH];
                 * for (int i = 0; i < op1.Length / FOR_LENGTH; i++)
                 *  go_next[i] = 0;
                 *
                 * for (int i = 0; i < op1.Length / FOR_LENGTH; i++)
                 * {
                 *  ops1[i] = op1.Remove(0, i * FOR_LENGTH);
                 *  //if (op1.Length/8 != i)
                 *  if (ops1[i].Length > FOR_LENGTH)
                 *      ops1[i] = ops1[i].Remove(FOR_LENGTH);
                 * }
                 * for (int i = 0; i < op1.Length / FOR_LENGTH; i++)
                 * {
                 *  ops2[i] = op2.Remove(0, i * FOR_LENGTH);
                 *  //if (op1.Length/8 != i)
                 *  if (ops2[i].Length > FOR_LENGTH)
                 *      ops2[i] = ops2[i].Remove(FOR_LENGTH);
                 * }
                 *
                 * for (int i = ops2.Length-1; i >= 0; i--)
                 * {
                 *  for (int ii = ops1.Length-1; ii >= 0; ii--)
                 *  {
                 *      ulong res = ulong.Parse(ops1[ii]) * ulong.Parse(ops2[i].ToString()) + go_next[ii];
                 *      string resi = res.ToString();
                 *      if (FOR_LENGTH == resi.Length)
                 *      {
                 *          scitance[ii].Append(resi);
                 *      }
                 *      else if (FOR_LENGTH > resi.Length)
                 *      {
                 *          scitance[ii].Append(resi);
                 *          for (int y = 0; y < FOR_LENGTH - resi.Length; y++)
                 *              scitance[ii].Append("0");
                 *      }
                 *      else
                 *      {
                 *          if (ii == 0)
                 *          {
                 *              scitance[ii].Append(resi);
                 *              continue;
                 *          }
                 *          go_next[ii - 1] = ulong.Parse(resi.Remove(resi.Length - FOR_LENGTH));
                 *          scitance[ii].Append(resi.Remove(0, resi.Length - FOR_LENGTH));
                 *      }
                 *  }
                 *
                 *
                 * }
                 *
                 * // secist scitance
                 * string ret = "0";
                 * for (int i = 0; i < scitance.Length; i++)
                 * {
                 *  ret = SumString(ret, scitance[i].ToString());
                 * }
                 *
                 * return ret;*/
            }

            //return "0";
        }
Example #7
0
 public static string SumString(string op1, string op2)
 {
     return(Math_v2.SumString(op1, op2));
 }