+// ========================================
+// RPN command code, written by divVerent
+// Last updated: December 28th, 2011
+// ========================================
+
string rpn_pop()
{
if(rpn_sp > 0) {
float rpn_getf() { return stof(rpn_get()); }
float rpn_popf() { return stof(rpn_pop()); }
-void rpn_pushf(float f) { return rpn_push(ftos(f)); }
-void rpn_setf(float f) { return rpn_set(ftos(f)); }
+void rpn_pushf(float f) { return rpn_push(sprintf("%.9g", f)); }
+void rpn_setf(float f) { return rpn_set(sprintf("%.9g", f)); }
void GenericCommand_rpn(float request, float argc, string command)
{
{
case CMD_REQUEST_COMMAND:
{
- float i, j, f, n, f2, f3, rpnpos;
- vector rgb;
- string s, s2, c, rpncmd;
+ float i, j, f, f2, f3, rpnpos;
+ //vector rgb;
+ string s, s2, rpncmd;
if(!rpn_db)
{
if(argc >= 2)
{
- float rpnpos;
- string rpncmd;
- float f2, f3;
rpn_sp = 0;
rpn_error = FALSE;
for(rpnpos = 1; rpnpos < argc; ++rpnpos)
f = rpn_popf();
f2 = rpn_getf();
rpn_setf(f2 - f * floor(f2 / f));
+ } else if(rpncmd == "pow" || rpncmd == "**") {
+ f = rpn_popf();
+ rpn_setf(pow(rpn_getf(), f));
+ } else if(rpncmd == "bitand" || rpncmd == "&") {
+ f = rpn_popf();
+ rpn_setf(rpn_getf() & f);
+ } else if(rpncmd == "bitor" || rpncmd == "|") {
+ f = rpn_popf();
+ rpn_setf(rpn_getf() | f);
+ } else if(rpncmd == "bitxor" || rpncmd == "^") {
+ f = rpn_popf();
+ rpn_setf(rpn_getf() ^ f);
+ } else if(rpncmd == "and" || rpncmd == "&&") {
+ f = rpn_popf();
+ rpn_setf(rpn_getf() && f);
+ } else if(rpncmd == "or" || rpncmd == "||") {
+ f = rpn_popf();
+ rpn_setf(rpn_getf() || f);
+ } else if(rpncmd == "xor" || rpncmd == "^^") {
+ f = rpn_popf();
+ rpn_setf(!rpn_getf() != !f);
+ } else if(rpncmd == "bitnot") {
+ rpn_setf(~rpn_popf());
+ } else if(rpncmd == "not") {
+ rpn_setf(!rpn_popf());
} else if(rpncmd == "abs") {
rpn_setf(fabs(rpn_getf()));
} else if(rpncmd == "sgn") {
rpn_setf(floor(rpn_getf()));
} else if(rpncmd == "ceil" || rpncmd == "c") {
rpn_setf(ceil(rpn_getf()));
+ } else if(rpncmd == "exp") {
+ rpn_setf(exp(rpn_getf()));
+ } else if(rpncmd == "log") {
+ rpn_setf(exp(rpn_getf()));
+ } else if(rpncmd == "sin") {
+ rpn_setf(sin(rpn_getf()));
+ } else if(rpncmd == "cos") {
+ rpn_setf(cos(rpn_getf()));
} else if(rpncmd == "max") {
f = rpn_popf();
f2 = rpn_getf();
rpn_setf(bound(f3, f2, f));
} else if(rpncmd == "when") {
f = rpn_popf();
- f2 = rpn_popf();
- f3 = rpn_getf();
+ s = rpn_pop();
+ s2 = rpn_get();
if(f)
- rpn_setf(f3);
+ rpn_set(s2);
else
- rpn_setf(f2);
+ rpn_set(s);
} else if(rpncmd == ">" || rpncmd == "gt") {
f = rpn_popf();
rpn_setf(rpn_getf() > f);
i = stof(db_get(rpn_db, "stack.pointer"));
db_put(rpn_db, "stack.pointer", ftos(i+1));
db_put(rpn_db, strcat("stack.", ftos(i)), s);
+ if(!i)
+ db_put(rpn_db, "stack.pos", "0");
}
- if(!i)
- db_put(rpn_db, "stack.pos", "0");
} else if(rpncmd == "dbpop") {
i = stof(db_get(rpn_db, "stack.pointer"));
if(i)
} else if(rpncmd == "sprintf1s") {
s = rpn_pop();
rpn_set(sprintf(s, rpn_get()));
+ } else if(rpncmd == "eval") {
+ s = rpn_pop();
+ command = strcat(s, substring(command, argv_end_index(rpnpos), -1));
+ argc = tokenize_console(command);
+ rpnpos = -1;
} else {
rpn_push(cvar_string(rpncmd));
}
default:
case CMD_REQUEST_USAGE:
{
- print(" rpn EXPRESSION... - a RPN calculator.\n");
+ print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " rpn EXPRESSION...\n"));
print(" Operator description (x: string, s: set, f: float):\n");
print(" x pop -----------------------------> : removes the top\n");
print(" x dup -----------------------------> x x : duplicates the top\n");
print(" x x exch --------------------------> x x : swap the top two\n");
print(" /cvarname load --------------------> x : loads a cvar\n");
print(" /cvarname x def -------------------> : writes to a cvar\n");
- print(" f f add|sub|mul|div|mod|max|min ---> f : adds/... two numbers\n");
- print(" f f eq|ne|gt|ge|lt|le -------------> f : compares two numbers\n");
+ print(" f f add|sub|mul|div|mod|pow -------> f : adds/... two numbers\n");
+ print(" f f and|or|xor|bitand|bitor|bitxor > f : logical and bitwise operations\n");
+ print(" f f eq|ne|gt|ge|lt|le|max|min -----> f : compares two numbers\n");
print(" f neg|abs|sgn|rand|floor|ceil------> f : negates/... a number\n");
+ print(" f not|bitnot ----------------------> f : logical and bitwise negation\n");
+ print(" f exp|log|sin|cos -----------------> f : exponential function & Co.\n");
print(" f f f bound -----------------------> f : bounds the middle number\n");
print(" f1 f2 b when ----------------------> f : f1 if b, f2 otherwise\n");
print(" s s union|intersection|difference -> s : set operations\n");
print(" s /MD4 digest ---------------------> s : MD4 digest\n");
print(" s /SHA256 digest ------------------> s : SHA256 digest\n");
print(" s /formatstring sprintf1s ---------> s : sprintf with 1 string (pad, cut)\n");
+ print(" s eval ----------------------------> : does something eval\n");
print(" Set operations operate on 'such''strings'.\n");
print(" Unknown tokens insert their cvar value.\n");
return;
}
}
}
-
-float GameCommand_Generic(string command)
-{
- if(argv(0) == "help")
- {
- print(" rpn EXPRESSION... - a RPN calculator.\n");
- print(" Operator description (x: string, s: set, f: float):\n");
- print(" x pop -----------------------------> : removes the top\n");
- print(" x dup -----------------------------> x x : duplicates the top\n");
- print(" x x exch --------------------------> x x : swap the top two\n");
- print(" /cvarname load --------------------> x : loads a cvar\n");
- print(" /cvarname x def -------------------> : writes to a cvar\n");
- print(" f f add|sub|mul|div|mod|max|min ---> f : adds/... two numbers\n");
- print(" f f eq|ne|gt|ge|lt|le -------------> f : compares two numbers\n");
- print(" f neg|abs|sgn|rand|floor|ceil------> f : negates/... a number\n");
- print(" f f f bound -----------------------> f : bounds the middle number\n");
- print(" f1 f2 b when ----------------------> f : f1 if b, f2 otherwise\n");
- print(" s s union|intersection|difference -> s : set operations\n");
- print(" s shuffle -------------------------> s : randomly arrange elements\n");
- print(" /key /value put -------------------> : set a database key\n");
- print(" /key get --------------------------> s : get a database value\n");
- print(" x dbpush --------------------------> : pushes the top onto the database\n");
- print(" dbpop|dbget -----------------------> x : removes/reads DB's top\n");
- print(" dblen|dbat ------------------------> f : gets the DB's size/cursor pos\n");
- print(" dbclr -----------------------------> : clear the DB\n");
- print(" s dbsave|dbload--------------------> : save/load the DB to/from a file\n");
- print(" x dbins ---------------------------> : moves the top into the DB\n");
- print(" dbext|dbread ----------------------> x : extract/get from the DB's cursor\n");
- print(" f dbmov|dbgoto --------------------> : move or set the DB's cursor\n");
- print(" s localtime -----------------------> s : formats the current local time\n");
- print(" s gmtime --------------------------> s : formats the current UTC time\n");
- print(" time ------------------------------> f : seconds since VM start\n");
- print(" s /MD4 digest ---------------------> s : MD4 digest\n");
- print(" s /SHA256 digest ------------------> s : SHA256 digest\n");
- print(" s /formatstring sprintf1s ---------> s : sprintf with 1 string (pad, cut)\n");
- print(" Set operations operate on 'such''strings'.\n");
- print(" Unknown tokens insert their cvar value.\n");
- print(" maplist add map\n");
- print(" maplist remove map\n");
- print(" maplist shuffle\n");
- print(" maplist cleanup\n");
- print(" maplist maplist\n");
- print(" maplist lsmaps\n");
- print(" maplist lsnewmaps\n");
- print(" addtolist variable addedvalue\n");
- print(" records\n");
- print(" rankings (map argument optional)\n");
- print(" settemp cvar value\n");
- print(" settemp_restore\n");
- return TRUE;
- }
-
- else if(argv(0) == "rpn")
- {
\ No newline at end of file