Added NE and ISINF operands to RPN
authoralex <alex@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sun, 10 Mar 2002 14:48:59 +0000 (14:48 +0000)
committeralex <alex@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sun, 10 Mar 2002 14:48:59 +0000 (14:48 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@83 a5681a0c-68f1-0310-ab6d-d61299d08faa

src/rrd_rpncalc.c
src/rrd_rpncalc.h

index 7a7a124..818ef56 100644 (file)
@@ -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){
index 8fce2e9..4796695 100644 (file)
@@ -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;