From 299153f58eb985cf0986b30ea1f76ea1b415654e Mon Sep 17 00:00:00 2001 From: oetiker Date: Wed, 14 Feb 2007 18:54:29 +0000 Subject: [PATCH] new operator ABS added -- git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2@1008 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/doc/rrdgraph_rpn.pod | 4 ++++ program/src/rrd_rpncalc.c | 6 ++++++ program/src/rrd_rpncalc.h | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/program/doc/rrdgraph_rpn.pod b/program/doc/rrdgraph_rpn.pod index 6e31ea6d..b2a84dd9 100644 --- a/program/doc/rrdgraph_rpn.pod +++ b/program/doc/rrdgraph_rpn.pod @@ -127,6 +127,10 @@ B Convert angle in degrees to radians, or radians to degrees. +B + +Take the absolute value. + =item Set Operations B diff --git a/program/src/rrd_rpncalc.c b/program/src/rrd_rpncalc.c index a5ab61f9..972f486b 100644 --- a/program/src/rrd_rpncalc.c +++ b/program/src/rrd_rpncalc.c @@ -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; } diff --git a/program/src/rrd_rpncalc.h b/program/src/rrd_rpncalc.h index beccfd5e..35758082 100644 --- a/program/src/rrd_rpncalc.h +++ b/program/src/rrd_rpncalc.h @@ -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; -- 2.30.2