Esempio n. 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;
        }
Esempio n. 2
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;
        }
Esempio n. 3
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));
        }
Esempio n. 4
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;
        }
Esempio 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)
        {
            LongRational rational = new LongRational(this.Numerator, this.Denominator);

            return(rational.ToString(provider));
        }
Esempio n. 6
0
        /// <inheritdoc/>
        public override int GetHashCode()
        {
            LongRational self = new LongRational(this.Numerator, this.Denominator);

            return(self.GetHashCode());
        }