Esempio n. 1
0
        public static MyBigNumber Sum2MyBigNumbers(MyBigNumber myNmbr1, MyBigNumber myNmbr2)
        {
            int         smallerByAbs = MyBigNumber.SmallerByAbsIsFirstOrSecond(myNmbr1, myNmbr2);
            MyBigNumber bgrByAbs, smlrByAbs;
            int         signOfBigger = 0;

            if (smallerByAbs == 1)
            {
                smlrByAbs    = myNmbr1;
                bgrByAbs     = myNmbr2;
                signOfBigger = myNmbr2.SignNmbr;
            }
            else
            {
                smlrByAbs    = myNmbr2;
                bgrByAbs     = myNmbr1;
                signOfBigger = myNmbr1.SignNmbr;
            }
            string biggerAbsNmbrs  = bgrByAbs.PartDigits;
            string smallerAbsNmbrs = smlrByAbs.PartDigits;
            int    biggerAbsFlPos  = bgrByAbs.FloatPointPosition;
            int    smallerAbsFlPos = smlrByAbs.FloatPointPosition;
            int    biggerFlPPos    = 0;

            if (biggerAbsFlPos > smallerAbsFlPos)
            {
                biggerFlPPos    = biggerAbsFlPos;
                smallerAbsNmbrs = MyBigNumber.AddNmbrZero(smallerAbsNmbrs, -1 * (biggerAbsFlPos - smallerAbsFlPos));
            }
            else
            {
                biggerFlPPos   = smallerAbsFlPos;
                biggerAbsNmbrs = MyBigNumber.AddNmbrZero(biggerAbsNmbrs, -1 * (smallerAbsFlPos - biggerAbsFlPos));
            }
            if (smallerAbsNmbrs.Length < biggerAbsNmbrs.Length)
            {
                smallerAbsNmbrs = MyBigNumber.AddNmbrZero(smallerAbsNmbrs, biggerAbsNmbrs.Length - smallerAbsNmbrs.Length);
            }
            string newStrPartDigits;

            if ((myNmbr1.SignNmbr * myNmbr2.SignNmbr) >= 0)
            {
                newStrPartDigits = MyBigNumber.AddTwoLines(biggerAbsNmbrs, smallerAbsNmbrs);
            }
            else
            {
                newStrPartDigits = MyBigNumber.BiggerMinusSmaller(biggerAbsNmbrs, smallerAbsNmbrs);
            }
            var myNmbr3 = new MyBigNumber()
            {
                PartDigits = newStrPartDigits, SignNmbr = signOfBigger, FloatPointPosition = biggerFlPPos
            };
            string newStringVal = myNmbr3.Value();

            return(MyBigNumber.CreateMyBigNumber(newStringVal));
        }