ROL and ROR for RPN
Steve Shipway <[email protected]> Mon, 28 Apr 2014 00:37:06 +0000
| Newsgroups | gmane.comp.db.rrdtool.devel |
|---|---|
| Message-ID | <5820DC553954E44FA1A36C78323AD1483A305B5E@uxcn10-tdc06.UoA.auckland.ac.nz> |
So, splitting this idea out from the separate post on the predict function, I propose adding the new operations ROL and ROR to the RPN interpreter. They would rotate the top 3 items left or right, and have this effect on the stack ... 1,2,3,ROL --> 2,3,1 1,2,3,ROR --> 3,1,2 These allow more complex arithmetic to be performed and complement the existing EXC operator. A context-diff against 1.4 is attached for your consideration; it is pretty simple and implemented similarly to EXC. The modified files are rrd_rpncalc.h and rrd_rpncalc.c Steve Steve Shipway [email protected] _______________________________________________ rrd-developers mailing list [email protected] https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers
rol-ror.patch
(application/octet-stream, 2.3 KB)
*** rrd_rpncalc.c.orig 2014-04-28 10:37:52.886321588 +1200
--- rrd_rpncalc.c 2014-04-28 10:46:42.353046040 +1200
***************
*** 185,190 ****
--- 185,192 ----
add_op(OP_AVG, AVG)
add_op(OP_ABS, ABS)
add_op(OP_ADDNAN, ADDNAN)
+ add_op(OP_ROL, ROL)
+ add_op(OP_ROR, ROR)
#undef add_op
}
(*str)[offset] = '\0';
***************
*** 385,390 ****
--- 387,394 ----
match_op(OP_AVG, AVG)
match_op(OP_ABS, ABS)
match_op(OP_ADDNAN, ADDNAN)
+ match_op(OP_ROR, ROR)
+ match_op(OP_ROL, ROL)
#undef match_op
else if ((sscanf(expr, DEF_NAM_FMT "%n", vname, &pos) == 1)
&& ((rpnp[steps].ptr = (*lookup) (key_hash, vname)) !=
***************
*** 649,654 ****
--- 653,680 ----
rpnstack->s[stptr - 1] = dummy;
}
break;
+ case OP_ROL:
+ stackunderflow(2);
+ {
+ double dummy;
+
+ dummy = rpnstack->s[stptr];
+ rpnstack->s[stptr] = rpnstack->s[stptr - 2];
+ rpnstack->s[stptr - 2] = rpnstack->s[stptr - 1];
+ rpnstack->s[stptr - 1] = dummy;
+ }
+ break;
+ case OP_ROR:
+ stackunderflow(2);
+ {
+ double dummy;
+
+ dummy = rpnstack->s[stptr];
+ rpnstack->s[stptr] = rpnstack->s[stptr - 1];
+ rpnstack->s[stptr - 1] = rpnstack->s[stptr - 2];
+ rpnstack->s[stptr - 2] = dummy;
+ }
+ break;
case OP_EXP:
stackunderflow(0);
rpnstack->s[stptr] = exp(rpnstack->s[stptr]);
*** rrd_rpncalc.h.orig 2014-04-28 10:37:48.135588326 +1200
--- rrd_rpncalc.h 2014-04-28 10:38:09.581898492 +1200
***************
*** 19,25 ****
OP_ATAN, OP_SQRT, OP_SORT, OP_REV, OP_TREND, OP_TRENDNAN,
OP_ATAN2, OP_RAD2DEG, OP_DEG2RAD,
OP_PREDICT,OP_PREDICTSIGMA,
! OP_AVG, OP_ABS, OP_ADDNAN
};
typedef struct rpnp_t {
--- 19,26 ----
OP_ATAN, OP_SQRT, OP_SORT, OP_REV, OP_TREND, OP_TRENDNAN,
OP_ATAN2, OP_RAD2DEG, OP_DEG2RAD,
OP_PREDICT,OP_PREDICTSIGMA,
! OP_AVG, OP_ABS, OP_ADDNAN,
! OP_ROL, OP_ROR
};
typedef struct rpnp_t {
smime.p7s
(application/pkcs7-signature, 5.8 KB) - not displayed