示例#1
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="From">Number to copy from</param>
 /// <param name="MaxSize">Maximum size cells to copy</param>
 public LongIntBase(LongIntBase From, uint MaxSize)
 {
     size = From.size;
     coef = new ushort[MaxSize];
     numberBase = From.numberBase;
     Buffer.BlockCopy(From.coef, 0, coef, 0, size*sizeof(ushort));
 }
示例#2
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="From">Number to copy from</param>
 /// <param name="mode">Mode of copying (Full and References copying)</param>
 public LongIntBase(LongIntBase From, ConstructorMode mode)
 {
     numberBase = From.numberBase;
     size = From.size;
     if (mode == ConstructorMode.Copy)
         coef = (ushort[])From.coef.Clone();
     else
         if (mode == ConstructorMode.Assign)
             coef = From.coef;
 }
示例#3
0
 public ULongIntB(LongIntBase FromLongNumber, ConstructorMode mode)
     : base(FromLongNumber, mode)
 {
 }
示例#4
0
        // calculates result of division of two long numbers
        public static ULongIntB operator /(ULongIntB A, ULongIntB B)
        {
            LongIntBase Q = new LongIntBase(A.Base);
            LongIntBase R = new LongIntBase(B.Base);

            LongMath.Divide(A, B, out Q, out R, true, false);
            return new ULongIntB(Q, ConstructorMode.Assign);
        }
示例#5
0
        // calculates result of division of long number on short number
        public static ULongIntB operator /(ULongIntB A, ushort b)
        {
            if (b == 1)
                return new ULongIntB(A);

            ushort r = 0;
            LongIntBase Q = new LongIntBase(A.Base);

            LongMath.UShortDiv(A, b, out Q, out r);
            return new ULongIntB(Q, ConstructorMode.Assign);
        }
示例#6
0
        // calculates remainder of division of long number on short number
        public static ushort operator %(ULongIntB A, ushort b)
        {
            ushort r = 0;
            LongIntBase Q = new LongIntBase(A.Base);

            LongMath.UShortDiv(A, b, out Q, out r);
            return r;
        }
示例#7
0
 /// <summary>
 /// Copy contrtuctor
 /// </summary>
 /// <param name="From">Number to copy from</param>
 public LongIntBase(LongIntBase From)
 {
     numberBase = From.numberBase;
     coef = (ushort[])From.coef.Clone();
     size = From.size;
 }
示例#8
0
        /// <summary>
        /// Converts long number to decimal number in string
        /// </summary>
        /// <returns>System.String with long number coeficients</returns>
        public override string ToString()
        {
            if (size <= 0 || IsZero())
                return "0";

            StringBuilder sb = new StringBuilder();
            LongIntBase thisTemp = new LongIntBase(this);

            ushort currNumber = 0;
            bool notZero = (thisTemp.size > 1 || thisTemp.coef[0] != 0);

            while (notZero)
            {
                LongMath.UShortDivSafe(thisTemp, 10000, ref thisTemp, ref currNumber);

                int numberLength = LongMath.IntLength(currNumber);
                sb.Insert(0, currNumber);

                notZero = (thisTemp.size > 1 || thisTemp.coef[0] != 0);

                if (notZero)
                    if (numberLength < 4)
                        sb.Insert(0, "0", 4 - numberLength);
            }

            return sb.ToString();
        }
示例#9
0
        /// <summary>
        /// Assignes coeficients to other long
        /// number without recreating array
        /// </summary>
        /// <param name="What">Number to assign</param>
        public void AssignBase(LongIntBase What)
        {
            int i = 0;

            for (; i < What.size; ++i)
                coef[i] = What.coef[i];

            for (; i < size; ++i)
                coef[i] = 0;

            numberBase = What.numberBase;
            size = What.size;
        }
示例#10
0
        /// <summary>
        /// Constructs long number from number
        /// in string representation
        /// </summary>
        /// <param name="line">String with long number</param>
        /// <param name="Base">Coeficients notation base</param>
        /// <param name="coefLength">Length of coeficients array</param>
        public LongIntBase(string line, uint Base, uint coefLength)
        {
            numberBase = Base;
            string s = "";

            if (line[0] == '-')
                s = line.Substring(1);
            else
                s = line.Substring(0);

            LongIntBase temp = new LongIntBase(Base, coefLength);
            temp.size = 1;

            int index = 0;
            int charsRead = 0;
            ushort mulFull = 10000;
            ushort mulValue;

            ushort currValue = 0;
            while (charsRead < s.Length)
            {
                if (s.Length - (index + 1)*4 > 0)
                {
                    currValue = Convert.ToUInt16(s.Substring(index * 4, 4));
                    mulValue = mulFull;

                    charsRead += 4;
                }
                else
                {
                    string lastString = s.Substring(index * 4);
                    currValue = Convert.ToUInt16(lastString);
                    mulValue = (ushort)System.Math.Pow(10, lastString.Length);
                    charsRead += lastString.Length;
                }

                LongMath.UShortMulSafe(ref temp, mulValue);
                LongMath.Increment(ref temp, currValue);
                ++index;
            }

            coef = (ushort[])temp.coef.Clone();
            size = temp.size;
        }
示例#11
0
 public SLongIntD(LongIntBase FromLongNumber, LSign lSign, ConstructorMode mode)
     : this(FromLongNumber, mode)
 {
     sign = lSign;
 }
示例#12
0
        // calculates remainder of division of two long numbers
        public static ULongIntD operator %(ULongIntD A, ULongIntD B)
        {
            LongIntBase Q = new LongIntBase(A.Base);
            LongIntBase R = new LongIntBase(B.Base);

            LongMath.Divide(A, B, out Q, out R, false, true);
            return new ULongIntD(R, ConstructorMode.Assign);
        }