Пример #1
0
        /// <summary>Compute bits of Pi in the local machine.</summary>
        public static double ComputePi(long b)
        {
            double pi = 0;

            foreach (Bellard.Parameter p in Bellard.Parameter.Values())
            {
                pi = Modular.AddMod(pi, new Bellard.Sum(b, p, 1, null).GetValue());
            }
            return(pi);
        }
Пример #2
0
        /// <summary>
        /// Compute the value using
        /// <see cref="Montgomery.Mod(long)"/>
        /// .
        /// </summary>
        internal virtual double Compute_montgomery()
        {
            long   e = E.value;
            long   n = N.value;
            double s = 0;

            for (; e > E.limit; e += E.delta)
            {
                s  = Modular.AddMod(s, montgomery.Set(n).Mod(e) / (double)n);
                n += N.delta;
            }
            return(s);
        }
Пример #3
0
        /// <summary>
        /// Compute the value using
        /// <see cref="Modular.Mod(long, long)"/>
        /// .
        /// </summary>
        internal virtual double Compute_modular()
        {
            long   e = E.value;
            long   n = N.value;
            double s = 0;

            for (; e > E.limit; e += E.delta)
            {
                s  = Modular.AddMod(s, Modular.Mod(e, n) / (double)n);
                n += N.delta;
            }
            return(s);
        }
Пример #4
0
            internal virtual double Compute_modPow()
            {
                long   e = E.value;
                long   n = N.value;
                double s = 0;

                for (; e > E.limit; e += E.delta)
                {
                    s = Modular.AddMod(s, Two.ModPow(BigInteger.ValueOf(e), BigInteger.ValueOf(n)) /
                                       n);
                    n += N.delta;
                }
                return(s);
            }
Пример #5
0
            /// <summary>get the value of sigma</summary>
            public virtual double GetValue()
            {
                if (sigma.GetValue() == null)
                {
                    double d = 0;
                    for (int i = 0; i < parts.Length; i++)
                    {
                        d = Modular.AddMod(d, parts[i].Compute());
                    }
                    sigma.SetValue(d);
                }
                double s = Modular.AddMod(sigma.GetValue(), tail.Compute());

                return(parameter.isplus ? s : -s);
            }
Пример #6
0
 /// <summary>
 /// <inheritDoc/>
 ///
 /// </summary>
 public virtual Summation GetElement()
 {
     if (sigma.GetValue() == null)
     {
         int    i = 0;
         double d = 0;
         for (; i < parts.Length && parts[i].GetValue() != null; i++)
         {
             d = Modular.AddMod(d, parts[i].GetValue());
         }
         if (i == parts.Length)
         {
             sigma.SetValue(d);
         }
     }
     return(sigma);
 }
Пример #7
0
 /// <summary>
 /// <inheritDoc/>
 ///
 /// </summary>
 public virtual Org.Apache.Hadoop.Examples.PI.Math.Summation Combine(Org.Apache.Hadoop.Examples.PI.Math.Summation
                                                                     that)
 {
     if (this.N.delta != that.N.delta || this.E.delta != that.E.delta)
     {
         throw new ArgumentException("this.N.delta != that.N.delta || this.E.delta != that.E.delta"
                                     + ",\n  this=" + this + ",\n  that=" + that);
     }
     if (this.E.limit == that.E.value && this.N.limit == that.N.value)
     {
         double v = Modular.AddMod(this.value, that.value);
         Org.Apache.Hadoop.Examples.PI.Math.Summation s = new Org.Apache.Hadoop.Examples.PI.Math.Summation
                                                              (new ArithmeticProgression(N.symbol, N.value, N.delta, that.N.limit), new ArithmeticProgression
                                                                  (E.symbol, E.value, E.delta, that.E.limit));
         s.SetValue(v);
         return(s);
     }
     return(null);
 }
Пример #8
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);
        }