Exemplo n.º 1
0
        public static ExponentialNumber ExponentialNumberCreate(string value)
        {
            ExponentialNumber result = new ExponentialNumber();

            result.Order = GetExponentialFromString(value);
            result.Mantissa.Clear();
            result.Mantissa = GetMantissaFromString(value, _mantissaPattern);

            return(result);
        }
Exemplo n.º 2
0
        public static ExponentialNumber operator +(ExponentialNumber firstTerm, ExponentialNumber secondTerm)
        {
            if (firstTerm.Mantissa.Count == 0)
            {
                return(secondTerm);
            }

            ExponentialNumber result = new ExponentialNumber();

            firstTerm.CastToCanonicalFormBigNumbers();
            secondTerm.CastToCanonicalFormBigNumbers();

            short exponentialValue = secondTerm.Order > firstTerm.Order ? secondTerm.Order : firstTerm.Order;

            result.Order = exponentialValue;

            if (exponentialValue == firstTerm.Order)
            {
                secondTerm.СastExponentOfNumberToValue(exponentialValue);
            }
            else
            {
                firstTerm.СastExponentOfNumberToValue(exponentialValue);
            }

            AlignMantissas(firstTerm.Mantissa, secondTerm.Mantissa);

            if (firstTerm.Mantissa.First.Value > 0)
            {
                result.Mantissa = SumMantissasByteValue(firstTerm.Mantissa, secondTerm.Mantissa);
            }
            else
            {
                result.Mantissa = SumMantissasByteValue(secondTerm.Mantissa, firstTerm.Mantissa);
            }

            result.RoundingResult();

            if (result.Mantissa.First.Value != 0)
            {
                result.CastToCanonicalFormBigNumbers();
            }
            else
            {
                result.CastToCanonicalFormSmallNumbers();
            }


            return(result);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Input new number in exponential form. Example of correct input (1,54e+5). " +
                              $"Size of mantissa should be no more than {_sizeOfMantissa} characters");
            Console.WriteLine("If you want to see sum of added numbers press \"=\"");

            ExponentialNumber sum = new ExponentialNumber();

            while (true)
            {
                string input = Console.ReadLine().Trim();
                if (input.Contains("="))
                {
                    break;
                }

                string mantissa;
                short  order;

                try
                {
                    Validation.ParseString(input, out mantissa, out order);
                }
                catch (Exception x)
                {
                    Console.WriteLine(x.Message);
                    continue;
                }

                ExponentialNumber custNumber = ExponentialNumber.ExponentialNumberCreate(input);

                sum += custNumber;
            }

            Console.WriteLine(sum.ToString());

            Console.WriteLine("Press any key to continue:");
            Console.ReadKey();
        }