Code

new operator ABS added --
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 14 Feb 2007 18:54:29 +0000 (18:54 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 14 Feb 2007 18:54:29 +0000 (18:54 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@1008 a5681a0c-68f1-0310-ab6d-d61299d08faa

doc/rrdgraph_rpn.pod
src/rrd_rpncalc.c
src/rrd_rpncalc.h

index 6e31ea6d09916eda496096b02f23acb5ad7d6002..b2a84dd9daa4a1c55d3a354e9de577918e94cc14 100644 (file)
@@ -127,6 +127,10 @@ B<DEG2RAD, RAD2DEG>
 
 Convert angle in degrees to radians, or radians to degrees.
 
+B<ABS>
+
+Take the absolute value.
+
 =item Set Operations
 
 B<SORT, REV>
index a5ab61f9a2da7c526b14ebd770e0c541a0f19c16..972f486b023ed054a6bd2915543c71eb877015f9 100644 (file)
@@ -162,6 +162,7 @@ void rpn_compact2str(rpn_cdefds_t *rpnc,ds_def_t *ds_def,char **str)
          add_op(OP_RAD2DEG,RAD2DEG)
          add_op(OP_DEG2RAD,DEG2RAD)
          add_op(OP_AVG,AVG)
+         add_op(OP_ABS,ABS)
 #undef add_op
               }
     (*str)[offset] = '\0';
@@ -340,6 +341,7 @@ rpn_parse(void *key_hash,const char *const expr_const,long (*lookup)(void *,char
        match_op(OP_RAD2DEG,RAD2DEG)
        match_op(OP_DEG2RAD,DEG2RAD)
        match_op(OP_AVG,AVG)
+       match_op(OP_ABS,ABS)
 #undef match_op
 
 
@@ -779,6 +781,10 @@ rpn_calc(rpnp_t *rpnp, rpnstack_t *rpnstack, long data_idx,
                    }
                 }
                 break;
+            case OP_ABS:
+                stackunderflow(0);
+                rpnstack -> s[stptr] = fabs(rpnstack -> s[stptr]);
+                break;
            case OP_END:
                break;
        }
index beccfd5e5dc841e73f7385b6a97844913b5b2574..357580825df30b7dafe07ef407aa37e827c1d12b 100644 (file)
@@ -18,7 +18,7 @@ enum op_en {OP_NUMBER=0,OP_VARIABLE,OP_INF,OP_PREV,OP_NEGINF,
            OP_UN,OP_END,OP_LTIME,OP_NE,OP_ISINF,OP_PREV_OTHER,OP_COUNT,
            OP_ATAN,OP_SQRT,OP_SORT,OP_REV,OP_TREND,
            OP_ATAN2,OP_RAD2DEG,OP_DEG2RAD,
-           OP_AVG};
+           OP_AVG,OP_ABS};
 
 typedef struct rpnp_t {
     enum op_en   op;