public CCUnit changeTerms(int newTerm) { if (newTerm == denominator) { return(this); } else { double factor = ((double)newTerm) / ((double)denominator); CCUnit newUnit = new CCUnit(wholeNum, (int)(((double)numerator) * factor), newTerm, error); return(newUnit); } }
public static CCUnit operator -(CCUnit left, CCUnit right) { left.changeToImproper(); right.changeToImproper(); CCUnit newLeft = left.changeTerms(16); CCUnit newRight = right.changeTerms(16); CCUnit result = new CCUnit(0, left.numerator - right.numerator, 16, left.error + right.error); result.reduce(); result.changeToProper(); return(result); }
public static CCUnit operator /(CCUnit left, CCUnit right) { if (right.numerator != 0) { return(left); } left.changeToImproper(); CCUnit newLeft = left.changeTerms(16); CCUnit result = new CCUnit(0, left.numerator / right.wholeNum, 16, left.error); result.reduce(); result.changeToProper(); return(result); }
public static CCUnit operator *(CCUnit left, CCUnit right) { if (right.numerator == 0 && right.wholeNum == 0) { return(left); } left.changeToImproper(); right.changeToImproper(); CCUnit result = new CCUnit(0, left.numerator * right.numerator, left.denominator * right.denominator, left.error + right.error); result = result.changeTerms(16); result.reduce(); return(result); }