private static int Compare(Number num1, Number num2) { if (num1.IsNegative && !num2.IsNegative) { return(-1); } if (!num1.IsNegative && num2.IsNegative) { return(1); } var notationCalc = new NotationCalculator(num1.Notation, num1.Value, num2.Value); int resultOfComparingValues = notationCalc.Compare(num1.Value, num2.Value); if (num1.IsNegative && num2.IsNegative) { if (resultOfComparingValues == 0) { return(resultOfComparingValues); } return(resultOfComparingValues != -1 ? -1 : 1); } return(resultOfComparingValues); }
private static string GetSubtraction(Number num1, Number num2) { var notationCalculator = new NotationCalculator(_notation, num1.Value, num2.Value); string prefix = ""; int comparingResult = notationCalculator.Compare(num1.Value, num2.Value); if (!num1.IsNegative && !num2.IsNegative && comparingResult == 1) { prefix = "-"; notationCalculator = new NotationCalculator(_notation, num2.Value, num1.Value); } else if (num1.IsNegative ^ num2.IsNegative) { if (num1.IsNegative) { prefix = "-"; } notationCalculator = new NotationCalculator(_notation, num1.Value, num2.Value); return(prefix + notationCalculator.GetSum()); } else if (num1.IsNegative && num2.IsNegative) { if (comparingResult > -1) { notationCalculator = new NotationCalculator(_notation, num2.Value, num1.Value); return(notationCalculator.GetSubtraction()); } notationCalculator = new NotationCalculator(_notation, num1.Value, num2.Value); return("-" + notationCalculator.GetSubtraction()); } return(prefix + notationCalculator.GetSubtraction()); }
private static string GetDivision(Number num1, Number num2) { string prefix = ""; if (num1.IsNegative ^ num2.IsNegative) { prefix = "-"; } var notationCalculator = new NotationCalculator(_notation, num1.Value, num2.Value); return(prefix + notationCalculator.GetDivision()); }