Example #1
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
        }
Example #2
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy1(components);

            if (s == null)
            {
                return;
            }
            s.storeBx();
            UniversalValue X = s.X;

            if (X.isInt())
            {
                return;
            }
            double result = X.toReal();

            if (result < 0)
            {
                result = -Math.Floor(-result);
            }
            else
            {
                result = Math.Floor(result);
            }
            X.fromReal(result);
        }
Example #3
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy1(components);

            if (s == null)
            {
                return;
            }
            s.storeBx();
            if (s.X.isInt())
            {
                return;
            }
            double x        = s.X.toReal();
            bool   positive = true;

            if (x < 0.0)
            {
                positive = false;
                x        = -x;
            }
            double degr = Math.Floor(x);
            double sec  = (x - degr) * 3600.0;
            double min  = Math.Floor(sec / 60.0);

            sec -= min * 60.0;
            x    = degr + 0.01 * (min + sec * 0.01);
            s.X.fromReal(positive ? x : -x);
        }
        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);
        }
        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);
            }
        }
Example #6
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy1(components);

            if (s == null)
            {
                return;
            }
            s.storeBx();
            UniversalValue X = s.X;

            if (X.isInt())
            {
                X.fromInt(0);
                return;
            }
            double result   = X.toReal();
            bool   positive = true;

            if (result < 0)
            {
                result   = -result;
                positive = false;
            }
            result = result - Math.Floor(result);
            X.fromReal(positive ? result : -result);
        }
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _Stack(components);

            if (s.X.isEmpty())
            {
                return;
            }
            if (s.X.isInt())
            {
                s.X.fromInt(-s.X.toInt());
                return;
            }
            double value = s.X.toReal();

            if (double.IsNaN(value))
            {
                return;
            }
            if (double.IsNegativeInfinity(value))
            {
                s.X.fromReal(double.PositiveInfinity);
                return;
            }
            if (double.IsPositiveInfinity(value))
            {
                s.X.fromReal(double.NegativeInfinity);
                return;
            }
            s.X.fromReal(-value);
        }
Example #8
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);
        }
Example #9
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy1(components);

            if (s == null)
            {
                return;
            }
            s.storeBx();
            if (s.X.isInt())
            {
                return;
            }
            double x        = s.X.toReal();
            bool   positive = true;

            if (x < 0.0)
            {
                positive = false;
                x        = -x;
            }
            double degr = Math.Floor(x);
            double mins = (x - degr) * 100.0;

            if (mins >= 60.0)
            {
                s.X.fromReal(double.NaN);
                return;
            }
            x = degr + mins / 60.0;
            s.X.fromReal(positive ? x : -x);
        }
Example #10
0
        public override void execute(MK52_Host components, string command)
        {
            Register_Memory rm   = _RegMem(components);
            UniversalValue  ptrR = rm._registerAddress(rm.registerByName(command));

            _ExtMem(components).fromUV(ptrR);
        }
Example #11
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _Stack(components);

            s.storeBx();
            s.push();
            s.X.fromReal(UniversalValue.__EE);
        }
Example #12
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _Stack(components);

            //s.storeBx(); // in MK-52 the Bx is not updated here
            s.push();
            s.X.fromString(command);
        }
Example #13
0
 public Form1()
 {
     InitializeComponent();
     myRPN = new MK52_Host(KBD_Manager1, LCD_Manager1);
     myRPN.init(backgroundWorker1);
     timer1.Enabled = true;
     return;
 }
Example #14
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _Stack(components);

            s.storeBx();
            double x = s.X.toReal();

            s.X.fromReal(x * 1.7453292519943295e-2);
        }
Example #15
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _Stack(components);

            s.storeBx();
            double x = s.X.toReal();

            s.X.fromReal(x / 25.4);
        }
Example #16
0
        public override void execute(MK52_Host components, string command)
        {
            Program_Memory pm = _ProgMem(components);

            if (!pm.goSub(command))
            {
                return;
            }
            _Stack(components).setLabel_P(0, "Error: call stack full");
        }
Example #17
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _Stack(components);

            s.storeBx();
            s.push();
            double result = components._m_RPN_Functions.myRNG.NextDouble();

            s.X.fromReal(result);
        }
Example #18
0
        public override void execute(MK52_Host components, string command)
        {
            UniversalValue X = _Stack(components).X;

            _ExtMem(components).swapWithUV(X);
            if (X.isEmpty())
            {
                X.fromInt(0);
            }
        }
Example #19
0
        public virtual void advancePC(MK52_Host components)
        {
            Program_Memory pm = components._m_Program_Memory;

            pm.incrementCounter();
            while (!pm.isAtEnd() && pm.getCurrentLine().Length == 0)
            {
                pm.incrementCounter();
            }
        }
Example #20
0
        public override void execute(MK52_Host components, string command)
        {
            Program_Memory pm = _ProgMem(components);

            if (!pm.returnFromSub())
            {
                return;
            }
            _Stack(components).setLabel_P(0, "Error: stack busted!");
        }
Example #21
0
        public override void execute(MK52_Host components, string command)
        {
            SD_Manager sd = components.getSD();

            sd.deleteEntity(sd.getItemFromListing());
            int tmp = sd.listingPosition;

            sd.readFolderItems();
            sd.setListingPosition(tmp);
        }
Example #22
0
 public void init(MK52_Host parent)
 {
     for (int i = 0; i <= RPN_STACK_SIZE; i++)
     {
         _stackValues.Add(new UniversalValue());
     }
     clear();
     resetLabels();
     setDMode(DMODE_DEGREES);
 }
Example #23
0
 public void init(MK52_Host components)
 {
     _parent = components;
     _rst    = _parent._m_RPN_Stack;
     _emem   = _parent._m_Extended_Memory;
     for (int i = 0; i < REGISTER_MEMORY_NVALS; i++)
     {
         m_Values.Add(new UniversalValue());
     }
     clear();
 }
Example #24
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy1(components);

            if (s == null)
            {
                return;
            }
            s.storeBx();
            double         result = 1.0;
            UniversalValue X      = s.X;

            if (X.isReal())
            {
                result = Math.Pow(10.0, X.toReal());
                X.fromReal(result);
                return;
            }
            Int64 p = X.toInt();

            if (p > 300)
            {
                X.fromReal(double.PositiveInfinity);
                return;
            }
            if (p < -300)
            {
                X.fromInt(0);
                return;
            }
            if (0 <= p && p <= 18)
            {
                Int64 r2 = 1;
                while (p > 0)
                {
                    r2 *= 10L;
                    p--;
                }
                X.fromInt(r2);
                return;
            }
            while (p > 0)
            {
                result *= 10.0;
                p--;
            }
            while (p < 0)
            {
                result *= 0.1;
                p++;
            }
            X.fromReal(result);
        }
Example #25
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);
        }
Example #26
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy1(components);

            if (s == null)
            {
                return;
            }
            s.storeBx();
            bool result = s.X.toInt() > 0;

            s.X.fromInt(result? 0: 1);
        }
Example #27
0
        public override void execute(MK52_Host components, string command)
        {
            Register_Memory rm   = _RegMem(components);
            UniversalValue  ptrE = _ExtMem(components).getCurrentLine();
            UniversalValue  ptrR = rm._registerAddress(rm.registerByName(command));

            if (ptrE.isEmpty())
            {
                ptrR.fromInt(0);
                return;
            }
            ptrR.fromLocation(ptrE);
        }
Example #28
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy1(components);

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

            s.X.fromReal(1.0 / x);
        }
Example #29
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack s = _dealWithClergy1(components);

            if (s == null)
            {
                return;
            }
            s.storeBx();
            switch (s.XtoOctant())
            {
            case -1:
                break;

            case 0:
            case 4:
                s.X.fromInt(0);
                return;

            case 1:
            case 5:
                s.X.fromInt(1);
                return;

            case 2:
                s.X.fromReal(double.PositiveInfinity);
                return;

            case 3:
            case 7:
                s.X.fromInt(-1);
                return;

            case 6:
                s.X.fromReal(double.NegativeInfinity);
                return;

            default:
                break;
            }
            double result = s.XtoRadian();

            if (double.IsInfinity(result))
            {
                s.X.fromReal(double.NaN);
                return;
            }
            s.setTrigAccuracyWarning(result);
            result = Math.Tan(result);
            s.X.fromReal(result);
        }
Example #30
0
        public override void execute(MK52_Host components, string command)
        {
            RPN_Stack      st = _Stack(components);
            Program_Memory pm = _ProgMem(components);

            if (st.X.toReal() == 0.0)
            {
                pm.incrementCounter();
            }
            else
            {
                pm.setCounter(command);
            }
        }