public static State ProcessDigit(State currentState, int digit) { if (currentState.IsCalculated) { LogicManager.ResetState(currentState); } if (currentState.IsFractional) { currentState.FractionDigitCount++; double fractionDivider = Math.Pow(10, currentState.FractionDigitCount); if (currentState.CurrentValue < 0) { currentState.CurrentValue = currentState.CurrentValue - digit / fractionDivider; } else { currentState.CurrentValue = currentState.CurrentValue + digit / fractionDivider; } currentState.CurrentValue = Math.Round(currentState.CurrentValue, currentState.FractionDigitCount); } else { currentState.CurrentValue = currentState.CurrentValue * 10 + digit; } return currentState; }
public Engine() { _state = new State(); _state.CurrentValueChanged += delegate(object sender, EventArgs e) { this.OnValueChanged(e); }; }
private static void ResetState(State currentState) { currentState.PreviousValue = currentState.CurrentValue; currentState.CurrentValue = 0; currentState.FractionDigitCount = 0; currentState.IsCalculated = false; currentState.IsFractional = false; currentState.IsSequentialEvaluation = false; }
public State Evaluate(State currentState) { if (currentState.CurrentValue == 0) { throw new DivideByZeroException(); } currentState.CurrentValue = currentState.PreviousValue / currentState.CurrentValue; return currentState; }
public State GetState(State currentState) { currentState.CurrentValue = 0; currentState.FractionDigitCount = 0; currentState.IsCalculated = false; currentState.IsFractional = false; currentState.IsSequentialEvaluation = false; currentState.Operation = OperationManager.Empty; currentState.PreviousValue = 0; return currentState; }
public State GetState(State currentState) { string currentValue = currentState.CurrentValue.ToString(CultureInfo.InvariantCulture); int dotIndex = -1; if (currentState.IsFractional) { dotIndex = currentValue.IndexOf('.'); if (dotIndex == -1) { currentValue += "."; } } if (currentValue.Length == 1) { currentValue = "0"; } else { currentValue = currentValue.Substring(0, currentValue.Length - 1); dotIndex = currentValue.IndexOf('.'); if (dotIndex == -1) { currentState.FractionDigitCount = 0; currentState.IsFractional = false; } else { currentState.FractionDigitCount = currentValue.Length - dotIndex - 1; } } if (currentValue == "-") { currentValue = "0"; } currentState.CurrentValue = double.Parse(currentValue, NumberStyles.Float, CultureInfo.InvariantCulture); return currentState; }
public static State Evaluate(State currentState) { double bufferCurrentValue; if (!currentState.IsSequentialEvaluation) { currentState.IsSequentialEvaluation = true; bufferCurrentValue = currentState.CurrentValue; } else { bufferCurrentValue = currentState.PreviousValue; } currentState = currentState.Operation.Evaluate(currentState); currentState.IsCalculated = true; currentState.PreviousValue = bufferCurrentValue; return currentState; }
public State GetState(State currentState) { return LogicManager.ProcessDigit(currentState, 5); }
public State Evaluate(State currentState) { currentState.CurrentValue = currentState.PreviousValue - currentState.CurrentValue; return currentState; }
public State GetState(State currentState) { currentState.CurrentValue = 0; return currentState; }
public State GetState(State currentState) { currentState.CurrentValue = Math.Pow(currentState.CurrentValue, -1); return currentState; }
public State GetState(State currentState) { currentState = LogicManager.ProcessOperation(currentState, OperationManager.Plus); return LogicManager.Evaluate(currentState); }
public State GetState(State currentState) { return LogicManager.ProcessOperation(currentState, OperationManager.Divide); }
public State GetState(State currentState) { currentState.IsFractional = true; return currentState; }
public static State ProcessOperation(State currentState, IOperation operation) { currentState.IsCalculated = true; currentState.Operation = operation; return currentState; }
public State GetState(State currentState) { currentState.CurrentValue = currentState.PreviousValue * (currentState.CurrentValue / 100.0); currentState.IsCalculated = true; return currentState; }
public State Evaluate(State currentState) { return currentState; }
public State GetState(State currentState) { currentState.CurrentValue = Math.Sqrt(currentState.CurrentValue); currentState.IsCalculated = true; return currentState; }
public State GetState(State currentState) { return LogicManager.Evaluate(currentState); }
public State GetState(State currentState) { return LogicManager.ProcessOperation(currentState, OperationManager.Multiply); }
public State Evaluate(State currentState) { return(currentState); }