private string CheckPowers(string value, int index, string exponent, out bool powerSolved) { string result; powerSolved = false; if (m_powers.Count == 0) { return(exponent); } Power power = m_powers[m_powers.Count - 1]; if (index == power.parenIndex) { power.exponent = Convert.ToDouble(exponent); result = power.Solve().ToString(); ReplaceValueInSteps(power.GetExpression(), result); m_results.AddValue(m_rawValue); m_powers.Remove(power); powerSolved = true; return(result); } return(exponent); }
public void SolveTest1() { Power power = new DomainEntities.Power(3.0); power.exponent = 2.0; Assert.AreEqual(9.0, power.Solve()); }
private string Solve(bool includesParen) { string localExpression; string workExpress; double result = 0.0; string[] exponentValues; localExpression = m_steps.LastOrDefault(); if (string.IsNullOrWhiteSpace(localExpression)) { return(""); } workExpress = localExpression; if (includesParen) { workExpress = workExpress.Substring(1, workExpress.Length - 2); } if (localExpression.Contains("^")) { exponentValues = localExpression.Split('^'); if (exponentValues[0].IsNumeric() && exponentValues[1].IsNumeric()) { Power power = new Power(Convert.ToDouble(exponentValues[0])); result = power.Solve(Convert.ToDouble(exponentValues[1])); } } else { result = Convert.ToDouble(new DataTable().Compute(workExpress, null)); } if (m_steps.Count > 1) { m_steps.Remove(localExpression); } ReplaceValueInSteps(localExpression, result.ToString()); m_results.AddValue(m_rawValue); return(result.ToString()); }
public void SolveTest() { Power power = new DomainEntities.Power(2.0); Assert.AreEqual(8.0, power.Solve(3.0)); }