コード例 #1
0
        /// <summary>Get the sums for the Bellard formula.</summary>
        public static IDictionary <Bellard.Parameter, Bellard.Sum> GetSums <T>(long b, int
                                                                               partsPerSum, IDictionary <Bellard.Parameter, IList <T> > existing)
            where T : Container <Summation>
        {
            IDictionary <Bellard.Parameter, Bellard.Sum> sums = new SortedDictionary <Bellard.Parameter
                                                                                      , Bellard.Sum>();

            foreach (Bellard.Parameter p in Bellard.Parameter.Values())
            {
                Bellard.Sum s = new Bellard.Sum(b, p, partsPerSum, existing[p]);
                [email protected]("put " + s);
                sums[p] = s;
            }
            return(sums);
        }
コード例 #2
0
        /// <summary>Compute bits of Pi from the results.</summary>
        public static double ComputePi <T>(long b, IDictionary <Bellard.Parameter, T> results
                                           )
            where T : Container <Summation>
        {
            if (results.Count != Bellard.Parameter.Values().Length)
            {
                throw new ArgumentException("m.size() != Parameter.values().length" + ", m.size()="
                                            + results.Count + "\n  m=" + results);
            }
            double pi = 0;

            foreach (Bellard.Parameter p in Bellard.Parameter.Values())
            {
                Summation   sigma = results[p].GetElement();
                Bellard.Sum s     = new Bellard.Sum(b, p, 1, null);
                s.SetValue(sigma);
                pi = Modular.AddMod(pi, s.GetValue());
            }
            return(pi);
        }