Esempio n. 1
0
        public VeryLong Multiply(VeryLong other)
        {
            int numberDecimalPlaces      = GetDecimalPlaces();
            int numberDecimalPlacesOther = other.GetDecimalPlaces();
            int resultDecialPlaces       = numberDecimalPlaces + numberDecimalPlacesOther;

            other = RemoveDecimalPlaces(other);
            string integerStringCopy = _integerString;

            _integerString = _integerString.Replace(".", "");

            List <string> multiplicationResults = new List <string>();
            string        multiplicationResult  = GetZeros(1);
            int           currentLastDigit      = 0;
            int           currentLastDigitOther = 0;
            int           resultDigit           = 0;
            int           behalte    = 0;
            int           mult       = 0;
            int           indexOther = 0;
            int           index      = 0;

            while (Length() > index)
            {
                indexOther           = 0;
                behalte              = 0;
                multiplicationResult = GetZeros(index);

                while (other.Length() > indexOther || behalte != 0)
                {
                    currentLastDigit      = int.Parse(GetLastDigit(index));
                    currentLastDigitOther = int.Parse(other.GetLastDigit(indexOther));
                    mult                 = currentLastDigit * currentLastDigitOther + behalte;
                    behalte              = mult / 10;
                    resultDigit          = mult % 10;
                    multiplicationResult = multiplicationResult.Insert(0, resultDigit.ToString());
                    indexOther++;
                }

                index++;
                multiplicationResults.Add(multiplicationResult);
            }

            VeryLong mainResult = VeryLong.AddSummands(multiplicationResults);

            mainResult.SetDecimalPlaces(resultDecialPlaces);
            mainResult.RemoveLeadingZeros();

            _integerString = integerStringCopy;
            return(mainResult);
        }