public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy2(components);

            if (s == null)
            {
                return;
            }
            double valueX = s.X.toReal();
            double valueY = s.Y.toReal();
            double result = valueY / valueX;

            if (double.IsNaN(result) ||
                double.IsNegativeInfinity(result) ||
                double.IsPositiveInfinity(result) ||
                s.X.isReal() || s.Y.isReal())
            {
                s.pop(0); // store Bx, remove X
                s.X.fromReal(result);
                return;
            }
            Int64 frac = s.Y.toInt() % s.X.toInt();
            Int64 res  = s.Y.toInt() / s.X.toInt();

            s.pop(0); // store Bx, remove X
            if (frac == 0)
            {
                s.X.fromInt(res);             // exact division
            }
            else
            {
                s.X.fromReal(result);
            }
        }
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy2(components);

            if (s == null)
            {
                return;
            }
            double valueX = s.X.toReal();
            double valueY = s.Y.toReal();
            double result = valueY * valueX;

            if (result < UniversalValue.HUGE_NEGATIVE_AS_REAL ||
                UniversalValue.HUGE_POSITIVE_AS_REAL < result ||
                s.X.isReal() || s.Y.isReal())
            {
                s.pop(0); // store Bx, remove X
                s.X.fromReal(result);
                return;
            }
            Int64 res = s.Y.toInt() * s.X.toInt();

            s.pop(0); // store Bx, remove X
            s.X.fromInt(res);
        }
示例#3
0
        protected RPN_Stack _dealWithClergy2(MK52_Host components)
        {
            RPN_Stack s = _Stack(components);

            if (s.X.isEmpty() || s.Y.isEmpty())
            {
                return(null);
            }
            double valueX = s.X.toReal();
            double valueY = s.Y.toReal();

            if (double.IsNaN(valueX) && double.IsNaN(valueY))
            {
                s.pop(2); // remove Y, leave one NaN in X
                return(null);
            }
            if (double.IsNaN(valueX))
            {
                s.pop(1); // remove X, leave Y
                return(null);
            }
            if (double.IsNaN(valueY))
            {
                s.pop(2); // remove Y, leave X
                return(null);
            }
            return(s); // the rest of ariphmetics
        }
示例#4
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy2(components);

            if (s == null)
            {
                return;
            }
            double x = s.X.toReal();
            double y = s.Y.toReal();

            s.pop(0);
            if (x <= 0.0 || y <= 0.0)
            {
                s.X.fromReal(double.NaN);
                return;
            }
            if (y == 1.0)
            {
                s.X.fromReal(double.PositiveInfinity);
                return;
            }
            double result = Math.Log(y) / Math.Log(x);

            s.X.fromReal(result);
        }
示例#5
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s      = _dealWithClergy1(components);
            int       result = 1;

            if (s != null)
            {
                result = (int)(s.X.toInt() & 0x7FFF);
            }
            components._m_RPN_Functions.myRNG = new Random(result);
            s.pop(0);
        }
示例#6
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy2(components);

            if (s == null)
            {
                return;
            }
            bool valueX = s.X.toInt() > 0;
            bool valueY = s.Y.toInt() > 0;

            s.pop(0);
            s.X.fromInt((valueX || valueY) ? 1 : 0);
        }
示例#7
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy2(components);

            if (s == null)
            {
                return;
            }
            s.pop(0);
            UniversalValue X_ = s.X;
            UniversalValue Y_ = s.Bx;

            if (Y_.isEmpty())
            {
                X_.fromInt(1);
                return;
            }
            double result = 1.0;
            double x      = X_.toReal();

            if (Y_.isReal())
            {
                result = Math.Pow(x, Y_.toReal());
                X_.fromReal(result);
                return;
            }
            Int64 p  = Y_.toInt();
            Int64 p2 = p;

            if (x == 0.0 && p == 0) // special case
            {
                X_.fromInt(1);
                return;
            }
            if (x == 0.0 && p < 0)
            {
                X_.fromReal(double.PositiveInfinity);
                return;
            }
            while (p > 0)
            {
                result *= x;
                p--;
            }
            x = 1.0 / x;
            while (p < 0)
            {
                result *= x;
                p++;
            }
            if (p2 <= 0 || X_.isReal() || Math.Abs(result) > UniversalValue.HUGE_POSITIVE_AS_REAL)
            {
                X_.fromReal(result);
                return;
            }
            // Try to keep as integer
            Int64 result2 = X_.toInt();
            Int64 mul     = result2;

            while (p2 > 1)
            {
                result2 *= mul;
                p2--;
            }
            X_.fromInt(result2);
        }