Esempio n. 1
0
 public void IsDigit_KeyPad()
 {
     foreach (var cur in Enum.GetValues(typeof(VimKey)).Cast <VimKey>().Where(VimKeyUtil.IsKeypadNumberKey))
     {
         var keyInput = KeyInputUtil.VimKeyToKeyInput(cur);
         Assert.True(keyInput.IsDigit);
         Assert.True(keyInput.RawChar.IsSome());
         Assert.True(CharUtil.IsDigit(keyInput.Char));
     }
 }
Esempio n. 2
0
        public static double postfix_evaluation(string postfix)
        {
            double         result, op1, op2;
            Stack <double> stack = new Stack <double>();
            int            len   = (postfix.Length);

            for (int i = 0; i < len; i++)
            {
                string x = ""; double read_x = 0; char c = ' ';

                if (postfix[i] == ' ')
                {
                    continue;
                }

                #region multidigit_check
                //else if (char.IsDigit(postfix[i]))
                //{
                //int num = 0;

                //while (char.IsDigit(postfix[i]))
                //{
                //    num = num * 10 + (postfix[i] - '0');
                //    i++;
                //}
                //i--;
                //stack.Push(num);
                //}
                #endregion

                //If c is a number or decimal point
                else if (CharUtil.IsDigit(c = postfix[i]))
                {
                    x += c;
                    //The cycle reading includes a decimal point (for example, 8.88+7.777, here will be read in three times, the first cycle reads 8.88,
                    //the second time reads +, the third cycle reads 7.77)
                    while (i < len - 1 && CharUtil.IsDigit(c = postfix[++i]))
                    {
                        x += c;
                    }

                    //If any number contains ! replacing ! with - and then convert it into number
                    if (x.Contains("`"))
                    {
                        x = x.Replace("`", "-");
                    }

                    read_x = double.Parse(x);

                    //Read the data into the data stack
                    stack.Push(read_x);
                }

                else
                {
                    op1 = stack.Pop();
                    try
                    {
                        op2 = stack.Pop();
                    }
                    catch (Exception)
                    {
                        op2 = 0;
                    }
                    switch (postfix[i])
                    {
                    case '+':
                        result = (double)(op2 + op1);
                        stack.Push(result);
                        break;

                    case '-':
                        result = (double)(op2 - op1);
                        stack.Push(result);
                        break;

                    case '*':
                        result = (double)(op2 * op1);
                        stack.Push(result);
                        break;

                    case '/':
                        if (op1 == 0)
                        {
                            throw new MathError();
                        }
                        result = (double)(op2 / op1);
                        stack.Push(result);
                        break;

                    case '^':
                        result = (double)(Math.Pow(op2, op1));
                        stack.Push(result);
                        break;
                    }
                }
            }

            result = (double)stack.Pop();
            return(result);
            //Console.Write("\nAnswer:: " + result);
        }