List <object> CalculateBrackets(List <object> toCalculate) { List <object> toC = new List <object>(toCalculate); for (int i = 0; i < toC.Count; i++) { if (toC[i] is Calculation calc) { CalculationResult tmpres = calc.Result(); if (tmpres.Error != null) { throw new CalculationException(tmpres.Error); } toC[i] = tmpres.Result; if (i == 0) { throw new CalculationException("No bracket before first calculation!"); } if (!(toC[i - 1] is Bracket)) { throw new CalculationException("No brackets around calculation."); } if (i + 1 < toC.Count && toC[i + 1] is Bracket) { toC.RemoveAt(i + 1); // Before minus one so that the list isn't changed before removing this value. } toC.RemoveAt(i - 1); i--; // To fix iteration } } return(toC); }
static void Reset() { rational = BigRational.Zero; result = null; fractionIndex = 0; bracketCount = 0; calculation = new Calculation(rational); calculationString = string.Empty; VisibleDecimals = 10; ResultDecimals = 50; }
static void UpdateText() { result = calculation.Result(); SetResultText(null); if (calculationString.Length > 0 && !(calculationString.StartsWith('<') && calculationString.EndsWith('>'))) { txt.Text = Extensions.Extensions.AddSpacesToNumber(calculationString); } else { txt.Text = "0"; } string clcstr = calculation.ToString(true); clc.Text = clcstr ?? string.Empty; }