Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rational"/> struct.
        /// </summary>
        /// <param name="value">The <see cref="double"/> to create the instance from.</param>
        /// <param name="bestPrecision">Whether to use the best possible precision when parsing the value.</param>
        public Rational(double value, bool bestPrecision)
        {
            LongRational rational = new LongRational(Math.Abs(value), bestPrecision);

            this.Numerator   = (uint)rational.Numerator;
            this.Denominator = (uint)rational.Denominator;
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SignedRational"/> struct.
        /// </summary>
        /// <param name="value">The <see cref="double"/> to create the instance from.</param>
        /// <param name="bestPrecision">Whether to use the best possible precision when parsing the value.</param>
        public SignedRational(double value, bool bestPrecision)
        {
            var rational = LongRational.FromDouble(value, bestPrecision);

            this.Numerator   = (int)rational.Numerator;
            this.Denominator = (int)rational.Denominator;
        }
Пример #3
0
        /// <inheritdoc/>
        public bool Equals(SignedRational other)
        {
            var left  = new LongRational(this.Numerator, this.Denominator);
            var right = new LongRational(other.Numerator, other.Denominator);

            return(left.Equals(right));
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rational"/> struct.
        /// </summary>
        /// <param name="numerator">The number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken.</param>
        /// <param name="denominator">The number below the line in a vulgar fraction; a divisor.</param>
        /// <param name="simplify">Specified if the rational should be simplified.</param>
        public Rational(uint numerator, uint denominator, bool simplify)
        {
            LongRational rational = new LongRational(numerator, denominator, simplify);

            this.Numerator   = (uint)rational.Numerator;
            this.Denominator = (uint)rational.Denominator;
        }
Пример #5
0
        /// <inheritdoc/>
        public bool Equals(Rational other)
        {
            LongRational left  = new LongRational(this.Numerator, this.Denominator);
            LongRational right = new LongRational(other.Numerator, other.Denominator);

            return(left.Equals(right));
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rational"/> struct.
        /// </summary>
        /// <param name="value">The <see cref="double"/> to create the instance from.</param>
        /// <param name="bestPrecision">Whether to use the best possible precision when parsing the value.</param>
        public Rational(double value, bool bestPrecision)
        {
            var rational = LongRational.FromDouble(Math.Abs(value), bestPrecision);

            this.Numerator   = (uint)rational.Numerator;
            this.Denominator = (uint)rational.Denominator;
        }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SignedRational"/> struct.
        /// </summary>
        /// <param name="value">The <see cref="double"/> to create the instance from.</param>
        /// <param name="bestPrecision">Whether to use the best possible precision when parsing the value.</param>
        public SignedRational(double value, bool bestPrecision)
        {
            LongRational rational = new LongRational(value, bestPrecision);

            this.Numerator   = (int)rational.Numerator;
            this.Denominator = (int)rational.Denominator;
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SignedRational"/> struct.
        /// </summary>
        /// <param name="numerator">The number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken.</param>
        /// <param name="denominator">The number below the line in a vulgar fraction; a divisor.</param>
        /// <param name="simplify">Specified if the rational should be simplified.</param>
        public SignedRational(int numerator, int denominator, bool simplify)
        {
            if (simplify)
            {
                LongRational rational = new LongRational(numerator, denominator).Simplify();

                this.Numerator   = (int)rational.Numerator;
                this.Denominator = (int)rational.Denominator;
            }
            else
            {
                this.Numerator   = numerator;
                this.Denominator = denominator;
            }
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rational"/> struct.
        /// </summary>
        /// <param name="numerator">The number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken.</param>
        /// <param name="denominator">The number below the line in a vulgar fraction; a divisor.</param>
        /// <param name="simplify">Specified if the rational should be simplified.</param>
        public Rational(uint numerator, uint denominator, bool simplify)
        {
            if (simplify)
            {
                var rational = new LongRational(numerator, denominator).Simplify();

                this.Numerator   = (uint)rational.Numerator;
                this.Denominator = (uint)rational.Denominator;
            }
            else
            {
                this.Numerator   = numerator;
                this.Denominator = denominator;
            }
        }
Пример #10
0
        /// <summary>
        /// Converts the numeric value of this instance to its equivalent string representation using
        /// the specified culture-specific format information.
        /// </summary>
        /// <param name="provider">
        /// An object that supplies culture-specific formatting information.
        /// </param>
        /// <returns>The <see cref="string"/></returns>
        public string ToString(IFormatProvider provider)
        {
            var rational = new LongRational(this.Numerator, this.Denominator);

            return(rational.ToString(provider));
        }
Пример #11
0
        /// <inheritdoc/>
        public override int GetHashCode()
        {
            var self = new LongRational(this.Numerator, this.Denominator);

            return(self.GetHashCode());
        }