/// <summary> /// To add the current number and the selected operation to the current expression /// </summary> public void SetBasicMathOperation(BasicMathOperations pressedOperation) { //If the expression was calculated and any basic math operation was pressed, except for "=" if (buttonsState.EqualBtnPressed && (pressedOperation != BasicMathOperations.Equal)) { currentData.CurrentExpression = clearData.ClearExpression(currentData.CurrentExpression); buttonsState.NumberPadBtnPressed_Change(true); buttonsState.AdditionalOperationBtnPressed_Change(false); buttonsState.EqualBtnPressed_Change(false); } currentData.CurrentExpression = NewCurrentExpression(pressedOperation); try { currentData.CurrentNumber = pressedOperation == BasicMathOperations.Equal ? calculate.Calc(currentData.CurrentExpression).ToString() : clearData.ClearNumber(currentData.CurrentNumber); } catch (DivideByZeroException) { currentData.CurrentNumber = "Division by zero"; } catch (OverflowException) { currentData.CurrentNumber = "NaN"; } if (pressedOperation == BasicMathOperations.Equal) { buttonsState.EqualBtnPressed_Change(true); } buttonsState.NumberPadBtnPressed_Change(false); buttonsState.AdditionalOperationBtnPressed_Change(false); }
/// <summary> /// To add the current number and the selected operation to the current expression /// </summary> public void SetBasicMathOperation(BasicMathOperations pressedOperation) { //If the expression was calculated and any basic math operation was pressed, except for "=" if (buttonsState.EqualBtnPressed && (pressedOperation != BasicMathOperations.Equal)) { currentData.CurrentExpression = clearData.ClearExpression(currentData.CurrentExpression); buttonsState.NumberPadBtnPressed_Change(true); buttonsState.AdditionalOperationBtnPressed_Change(false); buttonsState.EqualBtnPressed_Change(false); } currentData.CurrentExpression = NewCurrentExpression(pressedOperation); currentData.CurrentNumber = pressedOperation == BasicMathOperations.Equal ? calculate.Calc(currentData.CurrentExpression).ToString() : clearData.ClearNumber(currentData.CurrentNumber); if (double.IsNaN(double.Parse(currentData.CurrentNumber)) || double.IsPositiveInfinity(double.Parse(currentData.CurrentNumber)) || double.IsNegativeInfinity(double.Parse(currentData.CurrentNumber))) { currentData.CurrentNumber = "Calculation error"; } if (pressedOperation == BasicMathOperations.Equal) { buttonsState.EqualBtnPressed_Change(true); } buttonsState.NumberPadBtnPressed_Change(false); buttonsState.AdditionalOperationBtnPressed_Change(false); }
/// <summary> /// Clears all data /// </summary> /// <remarks> /// At the same time, the numbers recorded in the memory are stored /// </remarks> public void ClearAll() { currentData.CurrentNumber = ClearNumber(currentData.CurrentNumber); currentData.CurrentExpression = ClearExpression(currentData.CurrentExpression); buttonsState.NumberPadBtnPressed_Change(true); buttonsState.AdditionalOperationBtnPressed_Change(false); buttonsState.EqualBtnPressed_Change(false); }