static void Main(string[] args)
 {
     //Creating our collection of tasks that compute the partial sums.
     List<Task<mpz_t>> tasks = new List<Task<mpz_t>>();
     //For loop for assigning a dynamic number of threads.
     for (int k = 0; k < numThreads; k++)
     {
         //DO NOT REMOVE! This is neccesary, because of how threading works. k will change each iteration, but tempk stays at whatever it is for that thread. The important part is, DO NOT TOUCH!
         int tempk = k;
         //Add a new method to compute for each k and add it to the tasks list.
         tasks.Add(Task.Factory.StartNew(() => {
            //Each one calculates a piece of the digits.
            return PSum_Arctan_2Term(numTerms / numThreads, tempk);
         }));
     }
     //Makes sure all are done before adding them up. If you don't it messes up the final value. One doesn't finish much faster than another thread, due to the nature of the algorithm.
     Task.WaitAll(tasks.ToArray());
     //Adding all the parts of the digits together in a loop.
     for (int j = 0; j < tasks.Count; j++)
     {
         //Adding all the parts of pi to the final static variable.
         final += tasks[j].Result;
     }
     //We write out a message so people see that the calculations are done, and the time it took.
     Console.WriteLine("#" + (numThreads * numTerms) + " numTerms of " + digits + " digits took " + (DateTime.Now - started) + " time. Your file is located at " + path + "pi_numTerms=" + (numThreads * numTerms) + "_digits=" + digits + ".txt");
     //Write to the file
     File.WriteAllText(path + "pi_numTerms=" + (numThreads * numTerms) + "_digits=" + digits + ".txt", "#" + (numThreads * numTerms) + " of " + digits + " digits " + (DateTime.Now - started) + Environment.NewLine + final);
     //Used so the program doesnt stop. Just press enter after the message appears to stop it.
     Console.ReadLine();
 }
Пример #2
0
 static void MpirCalcs()
 {
     mpz_t a = new mpz_t(12345678901234567890);
     mpz_t b = new mpz_t(9876543210987654321);
     mpz_t c = a * b;
     System.Console.WriteLine("{0}", c);
 }
Пример #3
0
 void CalcProd()
 {
     tq2.Wait();
     for (; primes[untilIndex] < Exponent * Exponent; untilIndex++, prod *= primes[untilIndex])
     {
         ;
     }
     tq2.Next();
 }
Пример #4
0
 static void Bar()
 {
     // [using-sample]
     using (mpz_t a = new mpz_t(12345678901234567890))
     using (mpz_t b = new mpz_t(9876543210987654321)) 
     using (mpz_t c = a * b)
     {
         System.Console.WriteLine("{0}", c.ToString());
     }
     // [/using-sample]
 }
Пример #5
0
 public mpz_t Xor(mpz_t x)
 {
     return (this ^ x);
 }
Пример #6
0
 public mpz_t And(mpz_t x)
 {
     return (this & x);
 }
Пример #7
0
 public mpz_t DivideExactly(uint x)
 {
     mpz_t z = new mpz_t();
     mpir.mpz_divexact_ui(z, this, x);
     return z;
 }
Пример #8
0
 public bool IsDivisibleBy(mpz_t x)
 {
     return mpir.mpz_divisible_p(this, x) != 0;
 }
Пример #9
0
        public mpz_t Divide(uint x, out int remainder)
        {
            mpz_t quotient = new mpz_t();
            uint uintRemainder = mpir.mpz_tdiv_q_ui(quotient, this, x);
            if(uintRemainder > (uint)int.MaxValue)
                throw new OverflowException();

            if(this >= 0)
                remainder = (int)uintRemainder;
            else
                remainder = -(int)uintRemainder;

            return quotient;
        }
Пример #10
0
 public mpz_t Divide(uint x, out mpz_t remainder)
 {
     mpz_t quotient = new mpz_t();
     remainder = new mpz_t();
     mpir.mpz_tdiv_qr_ui(quotient, remainder, this, x);
     return quotient;
 }
Пример #11
0
 public mpz_t Divide(mpz_t x)
 {
     return this / x;
 }
Пример #12
0
 public static mpz_t operator ^(mpz_t x, mpz_t y)
 {
     mpz_t z = new mpz_t();
     mpir.mpz_xor(z, x, y);
     return z;
 }
Пример #13
0
 public static mpz_t operator /(mpz_t x, uint y)
 {
     mpz_t quotient = new mpz_t();
     mpir.mpz_tdiv_q_ui(quotient, x, y);
     return quotient;
 }
Пример #14
0
        public static mpz_t operator /(mpz_t x, int y)
        {
            if (y >= 0) {
                mpz_t quotient = new mpz_t();
                mpir.mpz_tdiv_q_ui(quotient, x, (uint)y);
                return quotient;
            } else {
                mpz_t quotient = new mpz_t();
                mpir.mpz_tdiv_q_ui(quotient, x, (uint)(-y));
                mpz_t negQ = -quotient;
                quotient.Dispose();
                return negQ;
            }

        }
Пример #15
0
 public static mpz_t operator *(mpz_t x, uint y)
 {
     mpz_t z = new mpz_t();
     mpir.mpz_mul_ui(z, x, y);
     return z;
 }
Пример #16
0
 public MersenneNumber(int exponent)
 {
     Exponent = exponent;
     m        = Mpir.NET.mpz_t.One.ShiftLeft(exponent) - 1;
 }
Пример #17
0
 public mpz_t Multiply(mpz_t x)
 {
     return this * x;
 }
Пример #18
0
 public static mpz_t operator %(mpz_t x, mpz_t mod)
 {
     mpz_t z = new mpz_t();
     mpir.mpz_mod(z, x, mod);
     return z;
 }
Пример #19
0
        public mpz_t Divide(int x, out int remainder)
        {
            mpz_t quotient = new mpz_t();

            if(x >= 0)
            {
                remainder = (int)mpir.mpz_tdiv_q_ui(quotient, this, (uint)x);
                return quotient;
            }
            else
            {
                remainder = -(int)mpir.mpz_tdiv_q_ui(quotient, this, (uint)(-x));
                mpz_t res = -quotient;
                quotient.Dispose();
                return res;
            }
        }
Пример #20
0
        public static mpz_t operator %(mpz_t x, int mod)
        {
            if(mod < 0)
                throw new ArgumentOutOfRangeException();

            mpz_t z = new mpz_t();
            mpir.mpz_fdiv_r_ui(z, x, (uint)mod);
            return z;
        }
Пример #21
0
        public mpz_t Divide(uint x, out uint remainder)
        {
            // Unsure about the below exception for negative numbers. It's in Stefanov's 
            // original code, but that limitation isn't mentioned in 
            // http://gmplib.org/manual/Integer-Division.html#Integer-Division.
            //if(this.ChunkCount < 0)
            //    throw new InvalidOperationException("This method may not be called when the instance represents a negative number.");

            mpz_t quotient = new mpz_t();
            remainder = mpir.mpz_tdiv_q_ui(quotient, this, x);
            return quotient;
        }
Пример #22
0
 public static mpz_t operator %(mpz_t x, uint mod)
 {
     mpz_t z = new mpz_t();
     mpir.mpz_fdiv_r_ui(z, x, mod);
     return z;
 }
Пример #23
0
 public mpz_t Remainder(mpz_t x)
 {
     mpz_t z = new mpz_t();
     mpir.mpz_tdiv_r(z, this, x);
     return z;
 }
Пример #24
0
 public static mpz_t operator >>(mpz_t x, int shiftAmount)
 {
     mpz_t z = new mpz_t();
     mpir.mpz_tdiv_q_2exp(z, x, (uint)shiftAmount);
     return z;
 }
Пример #25
0
        public mpz_t DivideExactly(int x)
        {
            mpz_t z = new mpz_t();
            mpir.mpz_divexact_ui(z, this, (uint)x);

            if (x < 0) {
                mpz_t res = -z;
                z.Dispose();
                return res;
            } else {
                return z;
            }

        }
Пример #26
0
        public mpz_t ChangeBit(int bitIndex, int value)
        {
            mpz_t z = new mpz_t(this);

            if(value == 0)
                mpir.mpz_clrbit(z, (uint)bitIndex);
            else
                mpir.mpz_setbit(z, (uint)bitIndex);

            return z;
        }
Пример #27
0
 public mpz_t DivideMod(mpz_t x, mpz_t mod)
 {
     return (this * x.InvertMod(mod)) % mod;
 }
Пример #28
0
 /// Returns a new mpz_t which is the absolute value of this value.
 public mpz_t Abs()
 {
     mpz_t result = new mpz_t();
     mpir.mpz_abs(result, this);
     return result;
 }
Пример #29
0
 public mpz_t Or(mpz_t x)
 {
     return (this | x);
 }
Пример #30
0
 public mpz_t Add(mpz_t x)
 {
     return this + x;
 }
Пример #31
0
 public mpz_t Mod(mpz_t mod)
 {
     return (this % mod);
 }
Пример #32
0
 public mpz_t Subtract(mpz_t x)
 {
     return this - x;
 }