//Returns a string representing the division of the mathematical values the operands represent. public static string DivideStrings(string operand1, string operand2) { if (operand1 == "0") { return("0"); } if (operand2 == "1") { return(operand1); } if (DifferentiationTokenizer.IsNumber(operand1) && DifferentiationTokenizer.IsNumber(operand2)) { return((int.Parse(operand1) / int.Parse(operand2)).ToString()); } return(ToPrefixFormat(operand1, operand2, '/')); }
//Returns a string representing the addition of the mathematical values the operands represent. //Also support operatorSymbol = '-'. Then it acts as subtraction on the values. public static string AddStrings(string operand1, string operand2, char operatorSymbol = '+') { if (operand1 == "0") { return((operatorSymbol == '-') ? InvertString(operand2) : operand2); } if (operand2 == "0") { return(operand1); } if (DifferentiationTokenizer.IsNumber(operand1) && DifferentiationTokenizer.IsNumber(operand2)) { return((int.Parse(operand1) + (operatorSymbol == '+' ? 1 : -1) * int.Parse(operand2)).ToString()); } return(ToPrefixFormat(operand1, operand2, operatorSymbol)); }
//Returns a string representing the power function applied to the mathematical values the operands represent. public static string PowerStrings(string operand1, string operand2) { if (operand2 == "0") { return("1"); } if (operand2 == "1") { return(operand1); } if (operand1 == "0") { return("0"); } if (DifferentiationTokenizer.IsNumber(operand1) && DifferentiationTokenizer.IsNumber(operand2)) { return(((int)Math.Round(Math.Pow(int.Parse(operand1), int.Parse(operand2)))).ToString()); } return(ToPrefixFormat(operand1, operand2, '^')); }