Ejemplo n.º 1
0
        public BigNumber Log(int places)
        {
            BigNumber dst = new BigNumber();

            BigNumber.Log(this, dst, places);
            return(dst);
        }
Ejemplo n.º 2
0
        public BigNumber Log()
        {
            BigNumber dst = new BigNumber();

            BigNumber.Log(this, dst, numDefaultPlaces);
            return(dst);
        }
Ejemplo n.º 3
0
        static void Log10(BigNumber src, BigNumber dst, int places)
        {
            BigNumber tmp8    = new BigNumber();
            BigNumber tmp9    = new BigNumber();
            int       dplaces = places + 4;

            BigNumber.CheckLogPlaces(dplaces + 45);
            BigNumber.Log(src, tmp9, dplaces);
            BigNumber.Mul(tmp9, BN_lc_log10R, tmp8);
            BigNumber.Round(tmp8, dst, places);
        }
Ejemplo n.º 4
0
        static public void Power(BigNumber xx, BigNumber yy, BigNumber rr, int places)
        {
            int       iflag;
            BigNumber tmp8        = new BigNumber();
            BigNumber tmp9        = new BigNumber();
            int       M_size_flag = BigNumber.GetSizeofInt();

            if (yy.signum == 0)
            {
                BigNumber.Copy(BigNumber.One, rr);
                return;
            }

            if (xx.signum == 0)
            {
                BigNumber.SetZero(rr);
                return;
            }

            if (BigNumber.IsInteger(yy) > 0)
            {
                iflag = 0;

                if (M_size_flag == 2)            /* 16 bit compilers */
                {
                    if (yy.exponent <= 4)
                    {
                        iflag = 1;
                    }
                }
                else                             /* >= 32 bit compilers */
                {
                    if (yy.exponent <= 7)
                    {
                        iflag = 1;
                    }
                }

                if (iflag > 0)
                {
                    String sbuf = BigNumber.ToIntString(yy);
                    int    Exp  = Convert.ToInt32(sbuf);
                    BigNumber.IntPow(places, xx, Exp, rr);
                    return;
                }
            }

            tmp8 = new BigNumber();
            tmp9 = new BigNumber();

            BigNumber.Log(xx, tmp9, (places + 8));
            BigNumber.Mul(tmp9, yy, tmp8);
            BigNumber.Exp(tmp8, rr, places);
        }
Ejemplo n.º 5
0
        public static void DoTest()
        {
            BigNumber A = 0, B = 0, C = 0;
            BigNumber PI = new BigNumber();

            // assignment by string
            A = "12345";
            Console.WriteLine("assigned value was: " + A.ToFullString() + "(" + A.ToString() + ")");

            // assignment from hexadecimal string
            A = "0xff";
            Console.WriteLine("assigned value was: " + A.ToFullString() + "(" + A.ToString() + ")");

            A = "0x1ff";
            Console.WriteLine("assigned value was: " + A.ToFullString() + "(" + A.ToString() + ")");

            A = "0x123456789";
            Console.WriteLine("assigned value was: " + A.ToFullString() + "(" + A.ToString() + ")");

            A = "0xFeDcBafedcba";
            Console.WriteLine("assigned value was: " + A.ToFullString() + "(" + A.ToString() + ")");

            // assignment from binary string
            A = "%10001000";
            Console.WriteLine("assigned value was: " + A.ToFullString() + "(" + A.ToString() + ")");

            A = "%11011011100111000111000111100011010101010101";
            Console.WriteLine("assigned value was: " + A.ToFullString() + "(" + A.ToString() + ")");

            // assignment by double
            A = 123.45;
            B = 0.12345;
            Console.WriteLine("assigned value was: " + A.ToFullString() + "(" + A.ToString() + ")");

            // assignment by string in exponential form x = a*10^y. 10E3 = 10*10^^3 = 10000
            A = "10E3";     // 10E3 = 10*10^3 = 10000
            B = "1E4";      // 1E4  =  1*10^4 = 10000
            C = 10000;
            Console.WriteLine("assigned value was: " + A.ToFullString() + "(" + A.ToString() + ")");
            Console.WriteLine("10000 = " + A.ToFullString() + " = " + B.ToFullString() + " = " + C.ToFullString());

            A = 1; B = 2; C = 0;
            C = A + B;
            Console.WriteLine("the result of " + A.ToFullString() + "+" + B.ToFullString() + "=" + C.ToFullString());
            // addition of BigNumber + double
            C = A + 3.2;
            // addition of double + BigNumber
            C = 3.1 + B;
            A = "5.141592"; B = "2.91827";
            C = A - B;
            Console.WriteLine("the result of " + A.ToFullString() + "-" + B.ToFullString() + "=" + C.ToFullString());

            C = A * B;
            Console.WriteLine("the result of " + A.ToFullString() + "*" + B.ToFullString() + "=" + C.ToFullString());
            A = 5.0; B = 3.0;
            C = A * B;
            Console.WriteLine("the result of " + A.ToFullString() + "*" + B.ToFullString() + "=" + C.ToFullString());

            A = 4; B = 0.5;
            C = A.Pow(B);
            Console.WriteLine("the result of " + A.ToFullString() + " pow " + B.ToFullString() + "=" + C.ToFullString());

            A = 0.5; B = "5E-1";
            C = A.Pow(B, 16);
            Console.WriteLine("the result of " + A.ToFullString() + " pow " + B.ToFullString() + "=" + C.ToFullString());

            A = "1e3"; // "10E2"; //   "1E3 = 1000";
            C = A.Log10();
            Console.WriteLine("the result of " + A.ToFullString() + " Log10 =" + C.ToFullString());

            A = "10E3"; B = "1E4"; C = 10000;

            A = BigNumber.BN_E;
            C = A.Log();
            Console.WriteLine("the result of " + A.ToString() + " Log =" + C.ToFullString());

            A = 3.0;
            C = A.Rez();
            Console.WriteLine("the result of " + A.ToString() + " Rez =" + C.ToFullString());

            int NumPlaces = 4;

            A = 1.53456;
            C = A.Round(NumPlaces);
            Console.WriteLine("the result of " + A.ToString() + " Round(" + NumPlaces + ") =" + C.ToFullString());

            NumPlaces = 2;
            C         = A.Round(NumPlaces);
            Console.WriteLine("the result of " + A.ToString() + " Round(" + NumPlaces + ") =" + C.ToFullString());

            NumPlaces = 0;
            C         = A.Round(NumPlaces);
            Console.WriteLine("the result of " + A.ToString() + " Round(" + NumPlaces + ") =" + C.ToFullString());

            NumPlaces = 16;
            A         = 2.0;
            C         = A.Sqrt(NumPlaces);
            Console.WriteLine("the result of " + A.ToString() + " Sqrt(" + NumPlaces + ") =" + C.ToFullString());

            A = 1.0; B = 0;
            try
            {
                C = A / B;
            }
            catch (BigNumberException ex)
            {
                Console.WriteLine("Exception in operation: " + ex.Message);
            }

            A = 1.0;
            for (int i = 1; i <= 1000; i++)
            {
                A = A * i;
            }

            Console.WriteLine("the result of 1000!=" + A.ToFullString());
            A = A.Round(numDefaultPlaces);
            Console.WriteLine("the result of 1000!=" + A.ToString());

            DateTime before = DateTime.Now;

            NumPlaces = 5000;
            CalculatePiAGM(PI, NumPlaces);

            TimeSpan ts = DateTime.Now - before;

            Console.WriteLine("time for " + NumPlaces + " digits of PI: " + ts.TotalMilliseconds + "[ms]");
            Console.WriteLine(PI.ToFullString());

            Console.WriteLine("Press 'x' key to quit test");
            //while (true)
            //{
            //    ConsoleKeyInfo i = Console.ReadKey();
            //    if (i.KeyChar == 'x') break;
            //}
        }