示例#1
0
		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;
		}
示例#2
0
		public Engine()
		{
			_state = new State();
			_state.CurrentValueChanged += delegate(object sender, EventArgs e)
			{
				this.OnValueChanged(e);
			};
		}
示例#3
0
		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;
		}
示例#5
0
		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;
		}
示例#7
0
		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;
		}
示例#8
0
		public State GetState(State currentState)
		{
			return LogicManager.ProcessDigit(currentState, 5);
		}
示例#9
0
		public State Evaluate(State currentState)
		{
			currentState.CurrentValue = currentState.PreviousValue - currentState.CurrentValue;
			return currentState;
		}
示例#10
0
		public State GetState(State currentState)
		{
			currentState.CurrentValue = 0;
			return currentState;
		}
示例#11
0
		public State GetState(State currentState)
		{
			currentState.CurrentValue = Math.Pow(currentState.CurrentValue, -1);
			return currentState;
		}
示例#12
0
		public State GetState(State currentState)
		{
			currentState = LogicManager.ProcessOperation(currentState, OperationManager.Plus);
			return LogicManager.Evaluate(currentState);
		}
示例#13
0
		public State GetState(State currentState)
		{
			return LogicManager.ProcessOperation(currentState, OperationManager.Divide);
		}
示例#14
0
		public State GetState(State currentState)
		{
			currentState.IsFractional = true;
			return currentState;
		}
示例#15
0
		public static State ProcessOperation(State currentState, IOperation operation)
		{
			currentState.IsCalculated = true;
			currentState.Operation = operation;
			return currentState;
		}
示例#16
0
		public State GetState(State currentState)
		{
			currentState.CurrentValue = currentState.PreviousValue * (currentState.CurrentValue / 100.0);
			currentState.IsCalculated = true;
			return currentState;
		}
示例#17
0
		public State Evaluate(State currentState)
		{
			return currentState;
		}
示例#18
0
		public State GetState(State currentState)
		{
			currentState.CurrentValue = Math.Sqrt(currentState.CurrentValue);
			currentState.IsCalculated = true;
			return currentState;
		}
示例#19
0
		public State GetState(State currentState)
		{
			return LogicManager.Evaluate(currentState);
		}
示例#20
0
		public State GetState(State currentState)
		{
			return LogicManager.ProcessOperation(currentState, OperationManager.Multiply);
		}
示例#21
0
 public State Evaluate(State currentState)
 {
     return(currentState);
 }