private void _autoIncrement(int n, UniversalValue uv) { if (n < 0) { return; } if (n > 6) { return; } int delta = (n > 3) ? 1 : -1; if (uv.isInt()) { uv.fromInt(uv.toInt() + delta); return; } if (uv.isReal()) { // TODO: For compatibility, registers are converted to int! // Not sure, if this must be supported or changed //uv.fromReal(uv.toReal() + (double)delta); uv.fromInt(uv.toInt() + delta); return; } }
public void K_MtoX(int n) { //_rst.storeBx(); _rst.push(); if (n < 0 || n >= REGISTER_MEMORY_NVALS) { return; } UniversalValue uv = _registerAddress(n); if (uv.isEmpty()) { _rst.X.fromInt(0); return; } Int64 index = uv.toInt(); _autoIncrement(n, uv); if (index < 0 || index >= Extended_Memory.EXTENDED_MEMORY_NVALS) { _rst.X.fromInt(0); return; } index = index % 10000; _emem.setCounter((uint)index); _emem.toUV(_rst.X); if (_rst.X.isEmpty()) { _rst.X.fromInt(0); } }
protected void _executeLoop(MK52_Host components, string command, uint reg) { UniversalValue loopReg = _RegMem(components)._registerAddress((int)reg); Int64 t = loopReg.toInt(); if (t > 0) { loopReg.fromInt(t - 1); } if (loopReg.toInt() > 0) { _ProgMem(components).setCounter(command); } else { _ProgMem(components).incrementCounter(); } }
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); }
public void K_XtoM(int n) { if (n < 0 || n >= REGISTER_MEMORY_NVALS) { return; } UniversalValue uv = _registerAddress(n); if (uv.isEmpty()) { return; } Int64 index = uv.toInt(); _autoIncrement(n, uv); A_XtoM(index); }
public override void execute(MK52_Host components, string command) { RPN_Stack s = _dealWithClergy1(components); if (s == null) { return; } s.storeBx(); UniversalValue X = s.X; double result = X.toReal(); if (result >= 0.0) { return; } if (X.isReal()) { X.fromReal(-result); return; } X.fromInt(-X.toInt()); }
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); }