Пример #1
0
        private BitArray Subtraction() //11
        {
            var result = FirstOperand.ToInt() - SecondOperand.ToInt();

            ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            return(ThirdOperand);
        }
Пример #2
0
        private BitArray Multiplication() //12
        {
            var result = FirstOperand.ToInt() * SecondOperand.ToInt();

            ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            return(ThirdOperand);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override string GetParameterValue()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(FirstOperand.GetParameterValue());
            switch (Operation)
            {
            case MathOperation.Division:
                sb.Append("/");
                break;

            case MathOperation.Minus:
                sb.Append("-");
                break;

            case MathOperation.Multiplication:
                sb.Append("*");
                break;

            case MathOperation.Plus:
                sb.Append("+");
                break;
            }
            sb.Append(SecondOperand.GetParameterValue());

            return(sb.ToString());
        }
Пример #4
0
        private BitArray Addition() //10
        {
            var result = FirstOperand.ToInt() + SecondOperand.ToInt();

            ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            return(ThirdOperand);
        }
Пример #5
0
 private void ResetOperandsToDefault()
 {
     FirstOperand.Clear();
     FirstOperand = new StringBuilder("0");
     SecondOperand.Clear();
     SecondOperand = new StringBuilder("0");
 }
Пример #6
0
        private BitArray ReadInBase() //18
        {
            var bs      = SecondOperand.ToInt();
            var operand = GetStringFromDialog();

            if (bs > 36 || bs < 0)
            {
                return(BitArrayExtension.GetBitArray(0, 9));
            }
            try
            {
                operand = operand.ToUpper();

                int result = 0;
                for (int i = operand.Length - 1, mul = 0; i >= 0; i--, mul++)
                {
                    result += (int)Math.Pow(bs, mul) * (Char.IsDigit(operand[i]) ?
                                                        (int)Char.GetNumericValue(operand[i]) :
                                                        (operand[i] - 55));
                }
                FirstOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            }
            catch (Exception)
            {
                return(BitArrayExtension.GetBitArray(0, 9));
            }
            return(FirstOperand);
        }
Пример #7
0
        private void SwitchValues()
        {
            switch (operationStage)
            {
            case OperationStage.EnterFirstOperand:
            {
                SecondOperand.Reset();
                operationStage = OperationStage.EnterSecondOperand;
                break;
            }

            case OperationStage.EnterSecondOperand:
            {
                CalculateResult();
                MoveResultToFirstOperand();
                SecondOperand.Reset();
                operationStage = OperationStage.EnterSecondOperand;
                break;
            }

            case OperationStage.DisplayResult:
            {
                MoveResultToFirstOperand();
                SecondOperand.Reset();
                operationStage = OperationStage.EnterSecondOperand;
                break;
            }
            }
        }
Пример #8
0
        private BitArray Modulo() //14
        {
            var result = FirstOperand.ToInt() % SecondOperand.ToInt();

            ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            return(ThirdOperand);
        }
Пример #9
0
        private BitArray StrongDivision() //13
        {
            var result = FirstOperand.ToInt() / SecondOperand.ToInt();

            ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            return(ThirdOperand);
        }
Пример #10
0
        /// <inheritdoc/>
        public override ushort GetValue(Environment environment)
        {
            Console.WriteLine($"Evaluating {this}");
            var leftSide  = FirstOperand.GetValue(environment);
            var rightSide = SecondOperand.GetValue(environment);

            return((ushort)(leftSide & rightSide));
        }
Пример #11
0
        public void Execute()
        {
            double firstOperand  = 0;
            double secondOperand = 0;

            try
            {
                firstOperand  = double.Parse(PrepareToParse(FirstOperand.ToString()));
                secondOperand = double.Parse(PrepareToParse(SecondOperand.ToString()));
            }
            catch (System.FormatException e)
            {
                Console.WriteLine(e.Message);
            }
            double result = 0;

            switch (actionOperator)
            {
            case "+":
            {
                result = operacja.Addition(firstOperand, secondOperand);
                break;
            }

            case "-":
            {
                result = operacja.Substraction(firstOperand, secondOperand);
                break;
            }

            case "/":
            {
                result = operacja.Division(firstOperand, secondOperand);
                break;
            }

            case "x":
            {
                result = operacja.Multiplication(firstOperand, secondOperand);
                break;
            }

            case "%":
            {
                result = operacja.Percentage(firstOperand, secondOperand);
                break;
            }

            default:
            {
                Result = "0";
                break;
            }
            }
            Result = result.ToString().Replace(',', '.');
            ResetOperandsToDefault();
            ResetIsOperandChosen();
        }
        public override int GetHashCode()
        {
            var hashCode = -655746530;

            hashCode = hashCode * -1521134295 + FirstOperand.GetHashCode();
            hashCode = hashCode * -1521134295 + Operator.GetHashCode();
            hashCode = hashCode * -1521134295 + SecondOperand.GetHashCode();
            return(hashCode);
        }
Пример #13
0
        public override string GetStepParameters()
        {
            var parameters = new List <string>();

            parameters.Add(Operator != null ? Operator.ToStepValue() : "$");
            parameters.Add(FirstOperand != null ? FirstOperand.ToStepValue() : "$");
            parameters.Add(SecondOperand != null ? SecondOperand.ToStepValue() : "$");

            return(string.Join(", ", parameters.ToArray()));
        }
Пример #14
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = FirstOperand.GetHashCode();
         hashCode = (hashCode * 397) ^ SecondOperand.GetHashCode();
         hashCode = (hashCode * 397) ^ Operation.GetHashCode();
         return(hashCode);
     }
 }
Пример #15
0
 public string DisplayOperand()
 {
     if (isOperandChosen == false)
     {
         return(FirstOperand.ToString());
     }
     else
     {
         return(SecondOperand.ToString());
     }
 }
Пример #16
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Label != null ? Label.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (LeftPartIdentifier != null ? LeftPartIdentifier.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (FirstOperand != null ? FirstOperand.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SecondOperand != null ? SecondOperand.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Operation != null ? Operation.GetHashCode() : 0);
         return(hashCode);
     }
 }
Пример #17
0
 public void DelButton()
 {
     if (String.IsNullOrEmpty(Operator))
     {
         FirstOperand.Del();
         NotifyOfPropertyChange(() => Result);
     }
     else
     {
         SecondOperand.Del();
         NotifyOfPropertyChange(() => Result);
     }
 }
Пример #18
0
        protected override MutableObject Mutate(MutableObject mutable)
        {
            foreach (var entry in Scope.GetEntries(mutable))
            {
                var comparison = Comparison.GetValue(entry);

                var firstOperand  = FirstOperand.GetValue(entry);
                var secondOperand = SecondOperand.GetValue(entry);

                ResultTarget.SetValue(IfCompareMutator.ComparisonPredicates[comparison](firstOperand, secondOperand), entry);
            }

            return(mutable);
        }
Пример #19
0
        private BitArray GetNumInSecOperandBase() //17
        {
            var num = FirstOperand.ToInt();
            var bs  = SecondOperand.ToInt();

            if (bs > 36 || bs < 0)
            {
                ShowMessage("Incorrect Base");
                return(BitArrayExtension.GetBitArray(0, 9));
            }

            ShowMessage(ConvertToBase(num, bs));
            return(BitArrayExtension.GetBitArray(num, 1));
        }
Пример #20
0
        private BitArray Insert() //16
        {
            var position = SecondOperand.ToInt();

            var inRange = position < 9 && position >= 0;

            if (!inRange)
            {
                position %= OperandLenght;
            }

            FirstOperand[position] = ThirdOperand[position];

            return(FirstOperand);
        }
Пример #21
0
        public string ToFunctionName()
        {
            string ret = Operation;

            if (FirstOperand != string.Empty)
            {
                ret += "_" + FirstOperand.Replace("(", "MEM_").Replace(")", "").Replace("+", "_");

                if (SecondOperand != string.Empty)
                {
                    ret += "_" + SecondOperand.Replace("(", "MEM_").Replace(")", "").Replace("+", "_");
                }
            }

            return(ret);
        }
Пример #22
0
 public void PercentButton()
 {
     if (String.IsNullOrEmpty(Operator))
     {
         decimal result = Convert.ToDecimal(FirstOperand.FullPart);
         result = (result == 0 ? (decimal)(1f / 100f) : (decimal)(result / 100));
         FirstOperand.Equal(result);
     }
     else
     {
         decimal result = Convert.ToDecimal(SecondOperand.FullPart);
         result = (result == 0 ? (decimal)(1f / 100f) : (decimal)(result / 100));
         SecondOperand.Equal(result);
     }
     NotifyOfPropertyChange(() => Result);
 }
Пример #23
0
        /// <summary>
        /// Gets the parameter value.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="context">The context.</param>
        /// <returns>
        /// Parameter value.
        /// </returns>
        public override string GetParameterValue(RootModel rootModel, ActionExecutionContext context)
        {
            Assert.ArgumentNotNull(rootModel, "rootModel");
            Assert.ArgumentNotNull(context, "context");

            var leftVal  = FirstOperand.GetParameterValue(rootModel, context);
            var rightVal = SecondOperand.GetParameterValue(rootModel, context);

            double leftValueNumeric;
            double rightValueNumertic;

            bool isLeftValueNumeric  = double.TryParse(leftVal, NumberStyles.Any, CultureInfo.InvariantCulture, out leftValueNumeric);
            bool isRightValueNumeric = double.TryParse(rightVal, NumberStyles.Any, CultureInfo.InvariantCulture, out rightValueNumertic);

            if (isRightValueNumeric && isLeftValueNumeric)
            {
                switch (Operation)
                {
                case MathOperation.Plus:
                    return((leftValueNumeric + rightValueNumertic).ToString(CultureInfo.InvariantCulture));

                case MathOperation.Minus:
                    return((leftValueNumeric - rightValueNumertic).ToString(CultureInfo.InvariantCulture));

                case MathOperation.Multiplication:
                    return((leftValueNumeric * rightValueNumertic).ToString(CultureInfo.InvariantCulture));

                case MathOperation.Division:
                    return(rightValueNumertic == 0
                                   ? string.Empty
                                   : (leftValueNumeric / rightValueNumertic).ToString(CultureInfo.InvariantCulture));
                }
            }
            else
            {
                if (Operation == MathOperation.Plus)
                {
                    return(leftVal + rightVal);
                }
            }

            return(string.Empty);
        }
Пример #24
0
 /// <summary>
 /// Update the display text
 /// </summary>
 /// <param name="showResult">Display the result or the current calculation</param>
 private void UpdateDisplay(bool showResult = false)
 {
     if (!showResult)
     {
         if (Operation != CalculatorOperation.Unknown)
         {
             display.text = string.Format("{0} {1} {2}",
                                          FirstOperand,
                                          OperationToString(),
                                          SecondOperand != 0 ? SecondOperand.ToString() : "").Trim();
         }
         else
         {
             display.text = FirstOperand.ToString();
         }
     }
     else
     {
         display.text = Result.ToString();
     }
 }
Пример #25
0
        public void CalculateResult()
        {
            try
            {
                switch (Operation)
                {
                case ("+"):
                    Result = (FirstOperand.ToDouble() + SecondOperand.ToDouble()).ToDisplayString();
                    break;

                case ("-"):
                    Result = (FirstOperand.ToDouble() - SecondOperand.ToDouble()).ToDisplayString();
                    break;

                case ("*"):
                    Result = (FirstOperand.ToDouble() * SecondOperand.ToDouble()).ToDisplayString();
                    break;

                case ("/"):
                    Result = (FirstOperand.ToDouble() / SecondOperand.ToDouble()).ToDisplayString();
                    break;

                case ("%"):
                    Result = (FirstOperand.ToDouble() * SecondOperand.ToDouble() / 100D).ToDisplayString();
                    break;

                case ("√"):
                    Result = Math.Sqrt(SecondOperand.ToDouble()).ToDisplayString();
                    break;

                case ("1/x"):
                    Result = (1 / (SecondOperand.ToDouble())).ToDisplayString();
                    break;
                }
            }
            catch (Exception)
            {
                Result = "Error";
            }
        }
Пример #26
0
        public void ModifyOperand(string commandString)
        {
            if (operationStage == OperationStage.DisplayResult)
            {
                MoveResultToFirstOperand();
            }

            switch (commandString)
            {
            case ".":
            {
                GetCurrentOperandObject().SetHasAPoint(true);
                break;
            }

            case "%":
            {
                GetCurrentOperandObject().DivideBy100();
                break;
            }

            case "+/-":
            {
                GetCurrentOperandObject().Invert();
                break;
            }

            case "C":
            {
                FirstOperand.Reset();
                SecondOperand.Reset();
                ResultOperand.Reset();
                operationStage = OperationStage.EnterFirstOperand;
                break;
            }
            }
        }
Пример #27
0
 public void SetSecondOperandValueForTesting(double value)
 {
     SecondOperand.SetValue(value);
 }
Пример #28
0
        private string GetBinaryStringCommand()
        {
            string command = ThirdOperand.ToStr() + SecondOperand.ToStr() + FirstOperand.ToStr() + Operation.ToStr();

            return(command);
        }
Пример #29
0
        private string GetStringCommand()
        {
            string command = ThirdOperand.ToInt() + " " + SecondOperand.ToInt() + " " + FirstOperand.ToInt() + " " + Operation.ToInt();

            return(command);
        }
Пример #30
0
 private BitArray CycleShiftR() //23
 {
     ThirdOperand = new BitArray(FirstOperand);
     ThirdOperand = ThirdOperand.CycleShiftR(SecondOperand.ToInt());
     return(ThirdOperand);
 }