From: alex Date: Sun, 10 Mar 2002 14:48:59 +0000 (+0000) Subject: Added NE and ISINF operands to RPN X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3131a15c56556f058b17e9bf5cb8544f7b5b8e19;p=rrdtool-all.git Added NE and ISINF operands to RPN git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@83 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/program/src/rrd_rpncalc.c b/program/src/rrd_rpncalc.c index 7a7a1242..818ef562 100644 --- a/program/src/rrd_rpncalc.c +++ b/program/src/rrd_rpncalc.c @@ -137,8 +137,10 @@ void rpn_compact2str(rpn_cdefds_t *rpnc,ds_def_t *ds_def,char **str) add_op(OP_UNKN,UNKN) add_op(OP_UN,UN) add_op(OP_NEGINF,NEGINF) + add_op(OP_NE,NE) add_op(OP_PREV,PREV) add_op(OP_INF,INF) + add_op(OP_ISINF,ISINF) add_op(OP_NOW,NOW) add_op(OP_LTIME,LTIME) add_op(OP_TIME,TIME) @@ -286,8 +288,10 @@ rpn_parse(void *key_hash,char *expr,long (*lookup)(void *,char*)){ match_op(OP_UNKN,UNKN) match_op(OP_UN,UN) match_op(OP_NEGINF,NEGINF) + match_op(OP_NE,NE) match_op(OP_PREV,PREV) match_op(OP_INF,INF) + match_op(OP_ISINF,ISINF) match_op(OP_NOW,NOW) match_op(OP_LTIME,LTIME) match_op(OP_TIME,TIME) @@ -580,6 +584,19 @@ rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx, rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] >= rpnstack -> s[stptr] ? 1.0 : 0.0; stptr--; break; + case OP_NE: + if(stptr<1){ + rrd_set_error("RPN stack underflow"); + return -1; + } + if (isnan(rpnstack -> s[stptr-1])) + ; + else if (isnan(rpnstack -> s[stptr])) + rpnstack -> s[stptr-1] = rpnstack -> s[stptr]; + else + rpnstack -> s[stptr-1] = rpnstack -> s[stptr-1] == rpnstack -> s[stptr] ? 0.0 : 1.0; + stptr--; + break; case OP_EQ: if(stptr<1){ rrd_set_error("RPN stack underflow"); @@ -653,8 +670,15 @@ rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx, } rpnstack->s[stptr] = isnan(rpnstack->s[stptr]) ? 1.0 : 0.0; break; + case OP_ISINF: + if(stptr<0){ + rrd_set_error("RPN stack underflow"); + return -1; + } + rpnstack->s[stptr] = isinf(rpnstack->s[stptr]) ? 1.0 : 0.0; + break; case OP_END: - break; + break; } } if(stptr!=0){ diff --git a/program/src/rrd_rpncalc.h b/program/src/rrd_rpncalc.h index 8fce2e91..4796695c 100644 --- a/program/src/rrd_rpncalc.h +++ b/program/src/rrd_rpncalc.h @@ -13,7 +13,7 @@ enum op_en {OP_NUMBER=0,OP_VARIABLE,OP_INF,OP_PREV,OP_NEGINF, OP_DIV,OP_SIN, OP_DUP, OP_EXC, OP_POP, OP_COS,OP_LOG,OP_EXP,OP_LT,OP_LE,OP_GT,OP_GE,OP_EQ,OP_IF, OP_MIN,OP_MAX,OP_LIMIT, OP_FLOOR, OP_CEIL, - OP_UN,OP_END,OP_LTIME}; + OP_UN,OP_END,OP_LTIME,OP_NE,OP_ISINF}; typedef struct rpnp_t { enum op_en op;