Exemplo n.º 1
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));
        }
Exemplo n.º 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;
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
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)
            {
                var rational = new LongRational(numerator, denominator).Simplify();

                this.Numerator   = (int)rational.Numerator;
                this.Denominator = (int)rational.Denominator;
            }
            else
            {
                this.Numerator   = numerator;
                this.Denominator = denominator;
            }
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
0
        /// <inheritdoc/>
        public override int GetHashCode()
        {
            var self = new LongRational(this.Numerator, this.Denominator);

            return(self.GetHashCode());
        }