コード例 #1
0
        /// <summary>
        /// Returns the remainder when this object's value is divided by x.
        /// </summary>
        /// <param name="x">The divisor.</param>
        public FormattedNumber Remainder(FormattedNumber x)
        {
            CanonicalNumber OperationResult = Canonical.Remainder(x.Canonical);

            FormattedNumber Result = FromCanonical(OperationResult);

            return(Result);
        }
コード例 #2
0
        /// <summary>
        /// Returns the bitwise XOR of this object's value and x.
        /// </summary>
        /// <param name="x">The number.</param>
        public FormattedNumber BitwiseXor(FormattedNumber x)
        {
            CanonicalNumber OperationResult = Canonical.BitwiseXor(x.Canonical);

            FormattedNumber Result = FromCanonical(OperationResult);

            return(Result);
        }
コード例 #3
0
        /// <summary>
        /// Returns this object's value divided by a specified power of two.
        /// </summary>
        /// <param name="x">The number.</param>
        public FormattedNumber ShiftRight(FormattedNumber x)
        {
            CanonicalNumber OperationResult = Canonical.ShiftRight(x.Canonical);

            FormattedNumber Result = FromCanonical(OperationResult);

            return(Result);
        }
コード例 #4
0
        /// <summary>
        /// Returns the square root of this object's value.
        /// </summary>
        public FormattedNumber Sqrt()
        {
            CanonicalNumber OperationResult = Canonical.Sqrt();

            FormattedNumber Result = FromCanonical(OperationResult);

            return(Result);
        }
コード例 #5
0
        /// <summary>
        /// Returns the negation of a number: -x.
        /// </summary>
        /// <param name="x">The number.</param>
        public static FormattedNumber operator -(FormattedNumber x)
        {
            CanonicalNumber OperationResult = -x.Canonical;

            FormattedNumber Result = FromCanonical(OperationResult);

            return(Result);
        }
コード例 #6
0
        /// <summary>
        /// Returns the ratio of two numbers: x / y.
        /// </summary>
        /// <param name="x">The first number.</param>
        /// <param name="y">The second number.</param>
        public static FormattedNumber operator /(FormattedNumber x, FormattedNumber y)
        {
            CanonicalNumber OperationResult = x.Canonical / y.Canonical;

            FormattedNumber Result = FromCanonical(OperationResult);

            return(Result);
        }
コード例 #7
0
        /// <summary>
        /// Parse a string as a number.
        /// </summary>
        /// <param name="text">The string to parse.</param>
        /// <returns>
        /// An instance of <see cref="FormattedInvalid"/> if <paramref name="text"/> cannot be parsed as a number.
        /// An instance of <see cref="FormattedInteger"/> if the valid part of the parsed number is an integer.
        /// An instance of <see cref="FormattedReal"/> if <paramref name="text"/> can be parsed, but not as an integer.
        /// </returns>
        /// <exception cref="NullReferenceException"><paramref name="text"/> is null.</exception>
        public static FormattedNumber Parse(string text)
        {
            IBinaryIntegerParsingInfo      BinaryIntegerParsing      = new BinaryIntegerParsingInfo();
            IOctalIntegerParsingInfo       OctalIntegerParsing       = new OctalIntegerParsingInfo();
            IDecimalIntegerParsingInfo     DecimalIntegerParsing     = new DecimalIntegerParsingInfo();
            IHexadecimalIntegerParsingInfo HexadecimalIntegerParsing = new HexadecimalIntegerParsingInfo();
            IRealParsingInfo RealParsing = new RealParsingInfo();

            foreach (char c in text)
            {
                bool KeepParsing = false;

                if (BinaryIntegerParsing.StillParsing)
                {
                    BinaryIntegerParsing.Handler(c);
                    KeepParsing = true;
                }

                if (OctalIntegerParsing.StillParsing)
                {
                    OctalIntegerParsing.Handler(c);
                    KeepParsing = true;
                }

                if (DecimalIntegerParsing.StillParsing)
                {
                    DecimalIntegerParsing.Handler(c);
                    KeepParsing = true;
                }

                if (HexadecimalIntegerParsing.StillParsing)
                {
                    HexadecimalIntegerParsing.Handler(c);
                    KeepParsing = true;
                }

                if (RealParsing.StillParsing)
                {
                    RealParsing.Handler(c);
                    KeepParsing = true;
                }

                if (!KeepParsing)
                {
                    break;
                }
            }

            IParsingInfo Parsing          = new InvalidParsingInfo();
            int          LengthSuccessful = 0;

            BinaryIntegerParsing.UpdateBestParsing(ref Parsing, ref LengthSuccessful);
            OctalIntegerParsing.UpdateBestParsing(ref Parsing, ref LengthSuccessful);
            DecimalIntegerParsing.UpdateBestParsing(ref Parsing, ref LengthSuccessful);
            HexadecimalIntegerParsing.UpdateBestParsing(ref Parsing, ref LengthSuccessful);
            RealParsing.UpdateBestParsing(ref Parsing, ref LengthSuccessful);

            FormattedNumber Result = Parsing.GetResult(text);

            return(Result);
        }