Ejemplo n.º 1
0
        public MainWindow()
        {
            mGlobalKeyboardHook = new GlobalKeyboardHook();
            mGlobalKeyboardHook.KeyboardPressed += OnGlobalKeyPressed;

            InitializeComponent();

            mCalcCur  = null;
            mCalcList = new List <CalcItem>();
            mComboBoxCalc.ItemsSource = mCalcList;


            double res;

            //res = RegexFormulas.Eval("(99)+(-23-((3+101b)/(0xF0)+-0x123+(0+1+2-3/4*5%6pow7pow8--++----9)))");

            res = RegexFormulas.Eval("1-2pow-2");
            res = RegexFormulas.Eval("1+log2-3pow2");
            //res = RegexFormulas.Eval("-(1+2)");
            //res = RegexFormulas.Eval("100^165");
            //res = RegexFormulas.Eval("int(1111pow11111)");

            //RegexFormulas.Eval("0+1+2-3/4*5%6pow7pow8--++----9", out res);
        }
Ejemplo n.º 2
0
        private void CalText(string text)
        {
            //MenuItemDebug.Header = "[Debug] " + (mDebugMode == 0?"Both":mDebugMode == 1? "3rd":"Native");
            double resultNative = double.NaN;
            double result3rd    = double.NaN;

            mTextEqualitySign.Text = "=";
            bool isErrorDetected = false;

            if (mDebugMode == 0 || mDebugMode >= 2)
            {
                try
                {
                    RegexFormulas.EvalWarningFlags flags = RegexFormulas.EvalWarningFlags.None;
                    resultNative = RegexFormulas.Eval(text, ref flags);
                    if ((flags & RegexFormulas.EvalWarningFlags.DoubleToInt) != 0)
                    {
                        Console.WriteLine(RegexFormulas.EvalWarningFlags.DoubleToInt);
                        mTextEqualitySign.Text = "≈";
                    }
                }
                catch (ArgumentOutOfRangeException ea)
                {
                    isErrorDetected  = true;
                    mTextResult.Text = "OutOfRange:" + ea.Message;
                    resultNative     = double.NaN;
                }
                catch (OverflowException eof)
                {
                    isErrorDetected  = true;
                    mTextResult.Text = "Overflow:" + eof.Message;
                    resultNative     = double.NaN;
                }
                catch (DivideByZeroException ediv)
                {
                    isErrorDetected  = true;
                    mTextResult.Text = "DivideByZero";
                    resultNative     = double.NaN;
                }
                catch (Exception ex)
                {
                    //Console.WriteLine(ex.Message);
                    resultNative = double.NaN;
                }
            }

#if !ENABLE_DynamicExpresso
            if (mDebugMode == 0 || mDebugMode == 1)
            {
                try
                {
                    var result = mInterpreter.Eval(cb.Text);

                    if (result.GetType() == typeof(int))
                    {
                        result3rd = (int)result;
                    }
                    else if (result.GetType() == typeof(float))
                    {
                        result3rd = (double)((float)result);
                    }
                    else if (result.GetType() == typeof(double))
                    {
                        result3rd = (double)result;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    result3rd = double.NaN;
                }
            }
#else
            result3rd = resultNative;
#endif

            if (double.IsNaN(resultNative) && double.IsNaN(result3rd))
            {
                if (!isErrorDetected)
                {
                    mTextResult.Text = "----";
                }
                ;
                mTextResult.Opacity = 0.5;
                if (mCalcCur != null)
                {
                    mCalcCur.mCalcResult     = Double.NaN;
                    mCalcCur.mCalcTextResult = "";
                }
            }
            else
            {
                if (mCalcCur == null)
                {
                    mCalcCur = new CalcItem();
                }
                mCalcCur.mCalcText = text;

                if (!double.IsNaN(resultNative))
                {
                    mCalcCur.mCalcResult = resultNative;
                }
                else if (!double.IsNaN(result3rd))
                {
                    mCalcCur.mCalcResult = result3rd;
                }

                mCalcCur.mCalcTextResult = mCalcCur.mCalcResult.ToString();

                if (mDebugMode == 0)
                {
                    Console.WriteLine("Native:" + resultNative + " 3rd:" + result3rd);
                }


                {
                    UpdateResult();
                    if (mDebugMode == 0)
                    {
                        if ((!double.IsNaN(resultNative) && !double.IsNaN(result3rd) && Math.Abs(resultNative - result3rd) > 2) ||
                            (double.IsNaN(resultNative) && !double.IsNaN(result3rd)))
                        {
                            mTextResult.Text = "N:" + resultNative + " 3:" + result3rd;
                        }
                    }


                    mTextResult.Opacity = 1;
                }
            }
        }