private TFrac Norm(TFrac SimpleFractions) { TFrac fractions = SimpleFractions; if (fractions.Numerator == 0) { fractions.Denominator = 1; return(fractions); } fractions = Reduction(fractions); if (NOD(new List <int> { fractions.Numerator, fractions.Denominator }) != 0) { int nod = NOD(new List <int> { fractions.Numerator, fractions.Denominator }); fractions.Numerator /= nod; fractions.Denominator /= nod; } if (fractions.Denominator < 0) { fractions.Numerator *= -1; fractions.Denominator *= -1; } return(fractions); }
/// <summary> /// Минус /// </summary> public TFrac Minus() { TFrac otv = this.Copy(); otv.Denominator = this.Denominator; otv.Numerator = 0 - this.Numerator; return(otv); }
/// <summary> /// Обратное /// </summary> public TFrac Reverse() { TFrac otv = this.Copy(); otv.Denominator = this.Numerator; otv.Numerator = this.Denominator; return(otv); }
/// <summary> /// Деление /// </summary> public TFrac Division(TFrac a, TFrac b) { TFrac otv = a.Copy(); otv.Denominator = a.Denominator * b.Numerator; otv.Numerator = a.Numerator * b.Denominator; return(Norm(otv)); }
/// <summary> /// Произведение /// </summary> public TFrac Multiplication(TFrac a, TFrac b) { TFrac otv = a.Copy(); otv.Denominator = a.Denominator * b.Denominator; otv.Numerator = a.Numerator * b.Numerator; return(otv); }
/// <summary> /// Равно /// </summary> public bool Ravn(TFrac d) { TFrac otv = Difference(this, d); if (otv.Numerator == 0) { return(true); } return(false); }
/// <summary> /// Больше /// </summary> public bool More(TFrac d) { TFrac otv = Difference(this, d); if ((otv.Numerator > 0 && otv.Denominator > 0) || (otv.Numerator < 0 && otv.Denominator < 0)) { return(true); } return(false); }
/// <summary> /// Сумма /// </summary> public TFrac Add(TFrac b) { TFrac otv = b.Copy(); if (this.Denominator == b.Denominator) { otv.denominator = this.Denominator; otv.numerator = this.Numerator + b.Numerator; } else { int nok = NOK(Convert.ToInt32(this.Denominator), Convert.ToInt32(b.Denominator)); otv.denominator = nok; otv.numerator = this.Numerator * (nok / this.Denominator) + b.Numerator * (nok / b.Denominator); } return(Norm(otv)); }
public TFrac Reduction(TFrac SimpleFractions) { TFrac a = SimpleFractions; if ((SimpleFractions.Denominator < 0 && SimpleFractions.Numerator >= 0) || (SimpleFractions.Numerator < 0 && SimpleFractions.Denominator < 0)) { SimpleFractions.Numerator *= -1; SimpleFractions.Denominator *= -1; } var nod = NOD(new List <int> { a.Numerator, a.Denominator }); if (nod != 1) { a.Denominator /= nod; a.Numerator /= nod; } return(a); }
/// <summary> /// Разность /// </summary> public TFrac Difference(TFrac A, TFrac B) { //if (A.Numerator == 0) return Multiplication(Norm(B), new TFrac(-1, 1)); if (B.Numerator == 0) { return(Norm(A)); } TFrac otv = A.Copy(); TFrac a = Norm(A), b = Norm(B); if (a.Denominator == b.Denominator) { otv.Denominator = a.Denominator; otv.Numerator = a.Numerator - b.Numerator; } else { int nok = NOK(Convert.ToInt32(a.Denominator), Convert.ToInt32(b.Denominator)); otv.Denominator = nok; otv.Numerator = a.Numerator * (nok / a.Denominator) - b.Numerator * (nok / b.Denominator); } return(Norm(otv)); }