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