Пример #1
0
        }     //Add(uint)

        /**
         * Method Name: Mult <br>
         * Method Purpose: multiplies very large UInt's <br>
         *
         * <hr>
         * Date created: 10/15/2015 <br>
         *
         * <hr>
         * Notes on specifications, special algorithms, and assumptions:
         *   multiplies numbers together and accounts for overflow
         *
         * <hr>
         *   @param UInt that is to be multiplied by
         *   @return None
         */
        public void Mult(UInt z)
        {
            UInt[] toAdd = new UInt[count * 200];
            long   l;
            long   zeros = 0;
            int    index = 0;

            for (int i = 0; i < z.getCount(); i++)
            {
                for (int ii = 0; ii < 9; ii++)
                {
                    l = UInt32.Parse(z.getX()[i].ToString("D9").Substring(8 - ii, 1));

                    if (l == 0)
                    {
                        zeros += 1;
                        continue;
                    }
                    else
                    {
                        toAdd[index] = new UInt(Seperate(l, zeros)); //(long)(l * Math.Pow(10, zeros)
                        index       += 1;
                    }
                    zeros += 1;
                }
            }
            for (int i = 0; i < count + 1; i++)
            {
                setX(i, 0);
            }
            for (int i = 0; i < index; i++)
            {
                Add(toAdd[i]);
            }
        }//Mult(uint)
Пример #2
0
        }//UInt(uint)

        public UInt(UInt uIn)
        {
            count = uIn.getCount();
            for (int i = 0; i < count + 1; i++)
            {
                x[i] = uIn.getX()[i];
            }
        }//UInt(UInt)
Пример #3
0
        }//incCount

        /**
         * Method Name: Add <br>
         * Method Purpose: Adds very large UInt's <br>
         *
         * <hr>
         * Date created: 10/15/2015 <br>
         *
         * <hr>
         * Notes on specifications, special algorithms, and assumptions:
         *   Adds numbers together and accounts for overflow
         *
         * <hr>
         *   @param UInt that is being added to sum
         *   @return None
         */
        public void Add(UInt z)
        {
            long temp;
            uint quot   = 0;
            int  length = z.getCount();             //finds number of elements implemented

            for (int i = 0; i < length; i++)        //adds VL and z elements together
            {
                if (z.getX()[i] == 0)
                {
                    continue;
                }
                temp = x[i] + z.getX()[i];
                if (temp >= max)                    //checks for overflow
                {
                    quot      = (uint)(temp / max); //removes carry and adds it to next element over
                    x[i + 1] += quot;
                    x[i]      = (uint)(temp - (quot * max));
                    if (count <= i)
                    {
                        count = i + 1;
                    }
                }//if
                else
                {
                    x[i] = (uint)temp;                    //no overflow
                    if (count <= i)
                    {
                        count = i + 1;
                    }
                }
            }//for

            if (x[length] > max)                    //checks that carry doesn't cause next element to overflow
            {
                quot           = (x[length] / max);
                x[length + 1] += quot;
                x[length]     -= (quot * max);
                if (count <= length)
                {
                    count = length + 1;
                }
            } //if
             //}//else
        }     //Add(uint)