public Fraction16(IFraction fraction) { int numerator, denominator; _wholeNumber = (short)(FractionUtil.GetNormalizedRational(FractionUtil.ToInt32(fraction.WholeNumber), FractionUtil.ToInt32(fraction.Numerator), FractionUtil.ToInt32(fraction.Denominator, 1), out numerator, out denominator)); _numerator = (short)numerator; _denominator = (short)denominator; }
public Fraction16(short numerator, short denominator) { int n, d; _wholeNumber = (short)(FractionUtil.GetNormalizedRational(0, numerator, denominator, out n, out d)); _numerator = (short)n; _denominator = (short)d; }
public Fraction8(sbyte numerator, sbyte denominator) { int n, d; _hashCode = 0; _wholeNumber = (sbyte)(FractionUtil.GetNormalizedRational(0, numerator, denominator, out n, out d)); _numerator = (sbyte)n; _denominator = (sbyte)d; }
private int CompareTo(IFraction <int> other) { if (other == null) { return(1); } if (other is Fraction32) { return(CompareTo((Fraction32)other)); } int n, d; int w = FractionUtil.GetNormalizedRational(other.WholeNumber, other.Numerator, other.Denominator, out n, out d); int i = _wholeNumber.CompareTo(w); if (i != 0) { return(i); } if (_wholeNumber == 0) { if (_numerator == 0 || n == 0 || _denominator == d) { return(_numerator.CompareTo(n)); } } else { if (_numerator == 0) { return(n); } if (n == 0) { return(_numerator); } } long n1 = _numerator, d1 = _denominator, n2 = n, d2 = d; FractionUtil.ToCommonDenominator64(ref n1, ref d1, ref n2, ref d2); return(n1.CompareTo(n2)); }
private bool Equals(IFraction <int> other) { if (other == null) { return(false); } if (other is Fraction32) { return(Equals((Fraction32)other)); } int n, d; int w = FractionUtil.GetNormalizedRational(other.WholeNumber, other.Numerator, other.Denominator, out n, out d); if (_numerator == 0) { return(n == 0 && _wholeNumber == w); } return(_numerator == n && _denominator == d && _wholeNumber == w); }
public Fraction32(int numerator, int denominator) { _wholeNumber = FractionUtil.GetNormalizedRational(0, numerator, denominator, out numerator, out denominator); _numerator = numerator; _denominator = denominator; }