Beispiel #1
0
 //Overloading operators in next lines
 public static Fraction operator +(Fraction a, Fraction b)
 {
     Fraction result = new Fraction();
     result.Numerator = (a.Numerator * b.Denominator)
     + (a.Denominator * b.Numerator);
     result.Denominator = a.Denominator * b.Denominator;
     result.Normalize();
     return result;
 }
Beispiel #2
0
 public static Fraction operator -(Fraction a, Fraction b)
 {
     Fraction result = new Fraction();
     if (a.Numerator > b.Denominator)
     {
         result.Numerator = (a.Numerator * b.Denominator) - (a.Denominator * b.Numerator);
         result.Denominator = a.Denominator * b.Denominator;
     }
     else
     {
         result.Numerator = (a.Denominator * b.Numerator) - (a.Numerator * b.Denominator);
         result.Denominator = a.Denominator * b.Denominator;
     }
     result.Normalize();
     return result;
 }