示例#1
0
        /// <summary>
        /// Returns given number as string of number always in Exponent formn.
        /// </summary>
        private string Return_Force_Exponent_Notation(IBack_Parser Back_Parser, string comma_Type)
        {
            // Exponent notation expresses number as a product of coeficient and exponent
            // after the "E" character meaning exponent with subscripted decimal number
            // been base of current numeral system. Coeficient if is longer than one digit
            // it contains a comma sign right after the first digit.
            // https://en.wikipedia.org/wiki/Scientific_notation#E-notation

            string output = Back_Parser.Get_Coeficient;

            if (output.Length > 1)
            {
                output = output.Insert(1, comma_Type);
            }

            output += Exponent_Sign(Back_Parser.Numeral_System_Type);

            output += Back_Parser.Exponent_In_Numeral_System_To_String(Back_Parser.Get_Exponent_Value);

            if (Back_Parser.Numeral_System_Type > 14)
            {
                output += ")";
            }

            return(output);
        }
示例#2
0
        /// <summary>
        /// Returns given number as string in form of engineering or forced comma notation
        /// according to order of magnitue.
        /// </summary>
        private string Return_Normal_Notation(IBack_Parser Back_Parser, string comma_Type)
        {
            // Normal notation expresses number in engineering or forced comma notation according
            // to order of magnitue. For numbers that would need more than 30 digits (or long
            // as precition if precition of numeral systems is longer than 30) they would be
            // returned in exponent notation. If shorter than as it was described the number will be
            // returned in force radix base notation.
            short coeficient_Length = (short)Back_Parser.Get_Coeficient.Length;

            byte precition = Back_Parser.Numeral_System_Precition;

            if (precition < 30)
            {
                precition = 30;
            }

            if ((Back_Parser.Get_Exponent_Value > 0 && Back_Parser.Get_Exponent_Value < precition) ||
                (Back_Parser.Get_Exponent_Value <= 0 && coeficient_Length - Back_Parser.Get_Exponent_Value < precition))
            {
                return(Return_Force_Radix_Base_Notation(Back_Parser, comma_Type));
            }
            else
            {
                return(Return_Force_Exponent_Notation(Back_Parser, comma_Type));
            }
        }
        /// <summary>
        /// Returns given number in given positonal numeral system.
        /// </summary>
        private string Positional_Numeral_System(double number, Number_Notation Number_Notation, sbyte numeral_System_Type, string comma_Type)
        {
            Double_Precition_Decomposer Decomposer = new Double_Precition_Decomposer(number);

            IBack_Parser Back_Parser = Construnct_Positional_Back_Parser(numeral_System_Type, Decomposer);

            return((Decomposer.Is_Negative ? "-" : String.Empty) +
                   Return_Notation_Selector(Back_Parser, Number_Notation, comma_Type));
        }
示例#4
0
        /// <summary>
        /// Returns given number as string in form of engineering notation.
        /// </summary>
        private string Return_Engineering_Notation(IBack_Parser Back_Parser, string comma_Type)
        {
            // Engineering notation expresses number as a product of coeficient and exponent presented
            // as power of base of mumeral system, as in scientific notation but forced to round down
            // the exponent to full multplication of 3. As a consequence the comma sign
            // maybe placed somewhere between four of first significant digits of the coeficient.
            // https://en.wikipedia.org/wiki/Engineering_notation

            string output = Back_Parser.Get_Coeficient;

            short current_Exponent = Back_Parser.Get_Exponent_Value;

            byte comma_shift = 0;

            while (current_Exponent % 3 != 0)
            {
                comma_shift++;
                current_Exponent--;
            }

            if (comma_shift == 0)
            {
                if (Back_Parser.Get_Coeficient.Length > 1)
                {
                    output = output.Insert(1, comma_Type);
                }
            }
            else if (Back_Parser.Get_Coeficient.Length > comma_shift)
            {
                output = output.Insert(comma_shift + 1, comma_Type);
            }
            else if (comma_shift == Back_Parser.Get_Coeficient.Length)
            {
                output += '0';
            }
            else if (comma_shift == 2 && Back_Parser.Get_Coeficient.Length == 1)
            {
                output += "00";
            }

            output += Scientific_Exponent(Back_Parser.Exponent_In_Numeral_System_To_String(current_Exponent), Back_Parser.Numeral_System_Type);

            return(output);
        }
        /// <summary>
        /// Returns given number as string in form of number always rooted on zeroeth order of magnitude.
        /// </summary>
        private string Return_Force_Radix_Base_Notation(IBack_Parser Back_Parser, string comma_Type)
        {
            // Force radix base notation expresses number always rooted on (radix) zeroeth
            // order of magnitude no matter how many zeroes may need to print it.
            // In simplier cases the comma sign will be placed among digits or will be not printed
            // at all in cases of integer numbers not divisible by base of their numeral sytem.
            // Normalized notations methods in those simplier cases will call this method
            // to return forced radix base notation.

            StringBuilder output = new StringBuilder();

            if (Back_Parser.Get_Exponent_Value < 0)
            {
                output.Append("0,");

                for (int i = Back_Parser.Get_Exponent_Value + 1; i < 0; i++)
                {
                    output.Append(0);
                }

                output.Append(Back_Parser.Get_Coeficient);
            }
            else
            {
                output.Append(Back_Parser.Get_Coeficient);

                short comma_Position = (short)(Back_Parser.Get_Exponent_Value - output.Length + 1);

                if (comma_Position < 0)
                {
                    output.Insert(Back_Parser.Get_Exponent_Value + 1, comma_Type);
                }
                else if (comma_Position > 0)
                {
                    for (int i = 0; i < comma_Position; i++)
                    {
                        output.Append(0);
                    }
                }
            }

            return(output.ToString());
        }
示例#6
0
        /// <summary>
        /// Returns given number as string always in form of scientific notation.
        /// </summary>
        private string Return_Force_Scientific_Notation(IBack_Parser Back_Parser, string comma_Type)
        {
            // Scientific notation expresses number as a product of coeficient and exponent presented
            // as power of base of mumeral system. Coeficient if is longer than one digit it contains
            // a comma sign right after the first digit.
            // https://en.wikipedia.org/wiki/Scientific_notation

            string output = Back_Parser.Get_Coeficient;

            if (output.Length > 1)
            {
                output = output.Insert(1, comma_Type);
            }

            output += Scientific_Exponent(
                Back_Parser.Exponent_In_Numeral_System_To_String(Back_Parser.Get_Exponent_Value),
                Back_Parser.Numeral_System_Type);

            return(output);
        }
        /// <summary>
        /// Returns given number as string in form of scientifc or forced comma notation
        /// for short numbers.
        /// </summary>
        private string Return_Scienfic_Normalized_Notation(IBack_Parser Back_Parser, string comma_Type)
        {
            // Scienfic normalized notation expresses number in scienfic or forced radix base notation
            // according to order of magnitue and length of the number. For numbers that
            // in forced radix base notation would need to add zeroes to the number it would be
            // returned in scienfic notation. In other case the number will be returned
            // in force radix base notation.

            int precition = Back_Parser.Numeral_System_Precition;

            short exponent_Value = Back_Parser.Get_Exponent_Value;

            if ((exponent_Value > 0 && exponent_Value < precition) && exponent_Value <= 0 &&
                0 - Back_Parser.Get_Coeficient.Length - exponent_Value > precition)
            {
                return(Return_Force_Radix_Base_Notation(Back_Parser, comma_Type));
            }
            else
            {
                return(Return_Force_Scientific_Notation(Back_Parser, comma_Type));
            }
        }