/// <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; }
/// <inheritdoc/> public bool Equals(Rational other) { var left = new LongRational(this.Numerator, this.Denominator); var right = new LongRational(other.Numerator, other.Denominator); return(left.Equals(right)); }
/// <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; }
/// <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; } }
/// <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)); }
/// <inheritdoc/> public override int GetHashCode() { var self = new LongRational(this.Numerator, this.Denominator); return(self.GetHashCode()); }